« My first time snowboarding | Main | Trying out the new camera »

Word Documents with PHP

I've just had the need to automatically generate word documents for the [FAS website] and I have to say I was surprised quite how simple that was with PHP. Well its kinda a fudge in that all I do is write HTML that openoffice understands and set the doctype to msword... does the trick nicely and here is a quick example ([inspiration for this]:

$filename ="yourdoc.doc";
$fp = fopen($filename, "w");
$test = "here is something really important that must be in a word document - argh";
fputs($fp, $test);
fclose($fp);
header('Content-disposition: attachment; filename=$filename);
header("Content-Type: application/msword");
readfile($filename);

Of course I was extracting the data from a mysql database and parsing that into the document - quite please with that really.

Oh and page breaks when making .doc files in php are useful:
<p style="page-break-before: always" >

TrackBack

TrackBack URL for this entry:
http://krioma.net/cgi-bin/MT-3.38/mt-tb.cgi/479

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on January 29, 2011 4:57 AM.

The previous post in this blog was My first time snowboarding.

The next post in this blog is Trying out the new camera.

Many more can be found on the main index page or by looking through the archives.

Get Firefox! Valid XHTML 1.0! Valid CSS! RSS Feed BlogUniverse - listed Powered by Apache Creative Commons License ringsofsaturnrock's Most Interesting Photos on Flickriver

Powered by
Movable Type 3.38