I have a form created in Microsoft Word that I need to fill in via PHP. I have looked at PHPWord, but it looks like you can only create Word documents with it. I considered exporting the form to XML and editing it that way, but the formatting gets screwy from the export. Is there another way?
Asked
Active
Viewed 5,307 times
0
-
I guess not. Why don't you plunge yourself into developing a library for this? – Sujit Agarwal Jun 14 '11 at 13:14
-
When you say "fill-in" what do you actually mean? Are you trying to send data from a PHP form to the Word document form? If so you might find this helpful - http://social.msdn.microsoft.com/Forums/en-ZA/oxmlsdk/thread/a258aa11-2a63-48a6-b365-ed677c4385cb – Aaron Newton Jun 14 '11 at 13:20
-
I am trying to use PHP to take data from a MySQL database and fill in a table in an existing Microsoft Word document. Then save it and email it out. – Rob Jun 14 '11 at 13:22
-
You should clarify whether its an office ~2003 word document or an Office 2007/2010 document (if it uses the .docx file extension it's a 2007/2010). The latter is based on XML, while the former is a proprietary binary format. If you are working with 2003 documents I would highly recommend looking into some way of converting the files to some other format using word '03 on a windows machine. .rtf is a good choice, as most of Word's form/data stuff survives the conversion and .rtf files are fairly easy to parse. – freenatec Jun 14 '11 at 14:31
1 Answers
2
At the time of writing this, there is no direct solution.
You might want to have a look at the best answer for Create Word Document using PHP in Linux to get a hint (uses OpenOffice documents that you can change since they are XML+ZIP, and converts opendocument to .doc on cmdline).
Another alternative is - if you run your script on a windows server - to use the COM interface to speak with Word. See http://drewd.com/2007/01/25/reading-from-a-word-document-with-com-in-php for an example to read a file, and - by digging through the Word COM API - you can also change existing documents.
-
Yeah I should have specified that this is a Linux server. Checking the other link. – Rob Jun 14 '11 at 13:20