Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Create a word .doc file from a .doc template in php

I need to create a word document from a word template, its something like, we need to replace the few strings (say variables) in the template with the values.

Please tell how we can do this in PHP ( or cakePHP).

like image 693
Nidhin Baby Avatar asked Jan 04 '10 17:01

Nidhin Baby


People also ask

How do I convert a template to a Word document?

Click the top folder in the library and launch Template Manager. (See Open and Close Template Manager.) The Template Manager window appears. In the file list, select the templates you want to convert and click the Convert button.


3 Answers

I'd recommend checking out phpLiveDocx: http://www.phplivedocx.org/

And some other questions on SO that might be worth reading:

  • Use PHP to create a DOC file on a Unix Box based on an HTML webform selection
  • Create Word Document using PHP in Linux
  • Reading/Writing a MS Word file in PHP
  • create word doc file from linux command line
like image 196
Colin O'Dell Avatar answered Nov 17 '22 07:11

Colin O'Dell


The biggest problem you will run into is that the .doc format is binary in nature (see this question and this post by Joel).

Is there any reason you cannot using either an HTML formatted document (which word has been able to open for over 10 years) or a Rich Text File? Both of these are text based, and will cause you significantly less pain. They are, as a result, very easy to use a template with.

Alternatively, if you can be sure that the user will have a newer version of Office (2007+) then you could, though it is somewhat tricky, use a .docx document, which is actually a Zip Archive and XML data. You can implement this fairly simply by creating a .docx word file that has the template you need, renaming it to .zip, extracting the files, teaching your application to do the text replacement on this in-place file structure, re-zip it using PHP's ZipArchive class, and then sending that file (named .docx, of course).

like image 34
Dereleased Avatar answered Nov 17 '22 08:11

Dereleased


i think this will help you

docxtemplater-master

Generate docx from templates, https://github.com/edi9999/docxtemplater

phpdocx

PHP library for the dynamical generation of Word documents in docx format.

http://www.phpdocx.com/

like image 28
Myhome Stories Avatar answered Nov 17 '22 08:11

Myhome Stories