Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to generate a "true" Word .DOC?

Status
Not open for further replies.

rhyno2k

IS-IT--Management
Jun 9, 2001
222
US
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:
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);
?>
 
the php stuff is just fwrite or similar. so i suspect you need to check out the MS Office forum for advice on how to build a docx file from the new schemas (if you can't work the schemas out for yourself from the published docs).
 
Right, j. I imagine it is something in the MS Office Schema. (Heading to that forum tomorrow)

I just wanted to throw this out there to the community to see if anyone has experienced similar issues and may have found a fix/workaround...
 
there is a workaround ... and that is using COM to instantiate a copy of word and input the stuff directly. obviously only works if you can reach a windows platform that has a copy of MS word installed on it.

it may be that openoffice exposes a COM interface or that you could script a solution for openoffice on a non windows platform.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top