tags:

views:

86

answers:

5

Hi friends, I have to modify the uploaded .doc or .docx file in php. I googled but i only found how to read that but not as it is. I want the word file as it is and put text at the bottom of that MS Word file. How is this possible anyone know please reply.

Thanks,

+1  A: 

Documents in the DOCX format should be XML (zipped), so you can try to parse and modify them...

See here for details about the format.

Macmade
A: 

Well, I recommend saving files as XML. When you write a document in MS Word, go Save As -> Other Formats -> Choose XML here.

You will be still able to open the document in MS Word and it will be easy to edit XML with PHP DOM or SimpleXML.

To add some text at the bottom, you just need to add a new w:p element to the XML body:

<w:p w:rsidR="00CF175F" w:rsidRDefault="00CF175F">
<w:r>
<w:t>New text to be added</w:t>
</w:r>
</w:p>

W is a namespace. For Word 2007+ it is:

http://schemas.openxmlformats.org/wordprocessingml/2006/main

In the older XML format there are different namespaces so you will have to look at MS web pages to find which one is correct.

Richard Knop
A: 

Thanks for reply, Actualy i am uploading the .doc file and insert some data in that doc file at the end. And then the insert the url of .doc file into database. Then when i want that .doc file i will download that. If i convert it to xml the how it change in word document.

Word documents are XML. At least from MS Word 2007. And even 2003 was some kind of XML already but probably not valid.
Richard Knop
A: 

I have used following code :- $w='Test'; $fp = fopen('c:/text.doc', 'a+'); fwrite($fp, $w); fclose($fp);

It appended the string but not showing in the word document. When i changed the extension of doc file to xml then it shows the string at the end. why should not it showing in doc file.

Thanks,

Sachin
A: 

Hi, i have still searching on how to modify word document using php. I am not getting the proper result that i want. I want to add some data at the end of word document. The document will be doc or docx. For both i want the script or how can i go to that? If anybody has the script for modifying or adding data at the end of word document please reply.

Thanks,

Sachin