开发者

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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜