Forum Moderators: coopster

Message Too Old, No Replies

php to doc

export content to .doc document

         

omoutop

7:01 am on Jun 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hello there,

i was wondering if there is a way to export the results of a php script to a .doc document instead of a webpage.

I can do thi kind of export with excel, but this is kind easy since you get colum/row results and populate corresponding cells.

Now, if i have large tables with images and styles, is it possible to export those in a .doc file?

Thanks for any help/suggestion

phparion

7:29 am on Jun 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If I am reading you correctly then simply open a file wit .doc extension and write all the output in it. due to .doc extension it will be MS Word compatible file.

e.g

$fh = fopen("file.doc","W");
fwrite($fh,$output);
fclose($fh);

Scally_Ally

8:13 am on Jun 1, 2007 (gmt 0)

10+ Year Member



I have done it before in a similar way to forcing a download of an excel spreadsheet, by using the msdoc mime type (application/msword).

On there i formatted simple text and fonts (ms word parses all the fonts etc for you and displays). Although i have never tried it with complex table layouts or css.

I would presume it would work in the same way.

Ally

omoutop

8:34 am on Jun 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



phparion:
yes that would be the easy solution, but browser opens the doc as if an html page (tested in IE as this is what my client is using - cant tell about FF or Opera). Now it may sounds ok, but if you use print preview you will see in header and footer of the printed page, many info that i don't want to show (path, vars, time, etc). Thats why i search for a "conversion" live tool/script, so as to open the file directly to Word/Open Word etc.

Scally_Ally:
it "partial" works, but without css styles. And any images must have an absoloute path (http://www.example.com/images/somefile.jpg.). This will be my final solution, if i cant find anything else.

oziman

8:45 am on Jun 1, 2007 (gmt 0)

10+ Year Member



Since I'm always confused about what I can and cannot link to on WebmasterWorld, I'll just say you should type in "php to ms word" on google and the top 5 results are pretty good.

G'luck.