Hi,
I've gotten to the point where I can produce a pretty stylish looking MS Word document from PHP using CSS and writing to a .DOC file. However, it remains an HTML file at its core, and not a true Word document.
The .DOC saves fine, looks great, but when editing the document and hitting Save for the first time, Word switches to Web Layout view, and creates a <docname>_files folder -- similar to what happens when saving a web page from Internet Explorer.
So it looks like the file is still HTML at heart. The initial file size after PHP generation is 13K. This balloons to (normal for .DOCs) 68K or so after saving.
So how can a 'true' .DOC be generated from PHP?
I need to have it so my users can edit the generated Word .DOC as is, stay in Print Layout view, without the extra _files folder junk.
Here's the pertinent code I'm using:
I've gotten to the point where I can produce a pretty stylish looking MS Word document from PHP using CSS and writing to a .DOC file. However, it remains an HTML file at its core, and not a true Word document.
The .DOC saves fine, looks great, but when editing the document and hitting Save for the first time, Word switches to Web Layout view, and creates a <docname>_files folder -- similar to what happens when saving a web page from Internet Explorer.
So it looks like the file is still HTML at heart. The initial file size after PHP generation is 13K. This balloons to (normal for .DOCs) 68K or so after saving.
So how can a 'true' .DOC be generated from PHP?
I need to have it so my users can edit the generated Word .DOC as is, stay in Print Layout view, without the extra _files folder junk.
Here's the pertinent code I'm using:
Code:
<?php
$fp = fopen($filename, 'w+');
?>
Code:
<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word'>
<head>
<meta http-equiv=ContentType content='text/html; charset=windows1252'>
<meta name=ProgId content=Word.Document>
<!--[if gte mso 9]>
<xml>
<o:DocumentProperties>
<o:Title>Quote</o:Title>
<o:Author>Me</o:Author>
<o:Company>MyCo</o:Company>
</o:DocumentProperties>
</xml>
<xml>
<w:WordDocument>
<w:View>Print</w:View>
<w:Zoom>85</w:Zoom>
<w:DoNotOptimizeForBrowser/>
</w:WordDocument>
</xml>
<![endif]-->
...
<!-- CSS and HTML follows -->
Code:
<?php
fwrite($fp, $str); // $str = HTML content
fclose($fp);
?>