Using PHP create a Word document in Landscape
I use this code to create a MS Word document; however, I want to make it in landscape. Does anybody know how 开发者_StackOverflowto it? Thanks
$fp = fopen('test.doc', 'w+');
$str = "<html><body>Content</body></html>";
fwrite($fp, $str);
fclose($fp);
As far as I know, your code should not work. MS Word produces binary files so you need to use COM
object.
Here's an example:
<?php
$word = new COM("word.application") or die ("Could not initialise MS Word object.");
$word->Documents->Open(realpath("Sample.doc"));
// Extract content.
$content = (string) $word->ActiveDocument->Content;
echo $content;
$word->ActiveDocument->Close(false);
$word->Quit();
$word = null;
unset($word);
The example is taken from here: http://www.developertutorials.com/tutorials/php/extracting-text-from-word-documents-via-php-and-com-81/
精彩评论