Actually, this is much easier than you might think. The trick is to use the capability of excel and word to read html files
So just generate normal html, but use a content-type header line to force the browser to see this as a word or excel file: (using php)
header (“Content-type: application/msword”); or
header (“Content-type: application/vnd.ms-word”);
for word and
header (“Content-type: application/msexcel”); or
header (“Content-type: application/vnd.ms-excel”);
I have never seen any difference between msword and vnd.ms-word, so if anybody knows the difference, please respond.
Then you might want to define the local filename. This can be done using the content-disposition header:
header(“Content-Disposition: filename=\”invoice_$invoicenr.xls\”");
For excel, just start generating a html table. The full table is used as excel sheet with its rows and columns.
For word, just start generating html code. It is interpreted by word. Make sure to use a FULL url path if you want to include images.
Here is an example to generate a word document:
<?
$inr=10056; // invoice number
$item="usbst"; // article number
$itemdesc="Usb stick 512Mb"; // article descr
$price=6.49; // price
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: filename=\"invoice_$inr.doc\"");
Header("Expires: Wed, 14 Oct 1997 06:41:40 GMT");
Header("Cache-control: no-cache");
?>
<html>
<HEAD>
<style type="text/css">
body { font-family: "Microsoft Sans Serif";
font-size:10pt;
margin:0px;}
img { padding:0px;margin:0px;border: solid 0px white;}
</style>
</HEAD><BODY>
<img src="http://www.cosninix.com/blog49/themes/default/images/header750x100.jpg" width="100">
<div style="margin-left:12px;">
<p>Invoice #<?=$inr?></p>
<table width="100%">
<tr>
<td width="20%"><b><?=$item?></b></td>
<td width="40%"><?=$itemdesc?></td>
<td width="40%"><?=$price?></td>
</tr>
</table>
</body>
</html>
Click here to test it.

would you mind updating your blog with more details? It is highly helpful for me. Big thumb up for this blog post!
Nice blog post. Keep blogging. Please visit mine when you have the time. Thanks
Hi there! I simply want to give a huge thumbs up for the good info you could have right here on this post. I will probably be coming back to your weblog for extra soon.
I can see that you are are genuinely passionate about this! I am trying to build my own website and you’ve helped me with some great information.
My coder is trying to convince me to move to .net from PHP. I have always disliked the idea because of the expenses. But he’s tryiong none the less. I’ve been using Movable-type on various websites for about a year and am worried about switching to another platform. I have heard fantastic things about blogengine.net. Is there a way I can transfer all my wordpress content into it? Any kind of help would be really appreciated!
[...] Cosninix » Generating microsoft office documents (word, excel) on your webserver using php [...]
may you go in to higher detail with this specific article? i would like to learn much more about it, mainly the second paragraph
[...] Cosninix » Generating microsoft office documents (word, excel) on your webserver using php [...]
[...] Cosninix » Generating microsoft office documents (word, excel) on your webserver using php [...]
Sir, I think your article give refrence for preparation of my site. Waiting new blogpost related with niche. TY.
We are a group of volunteers and starting a new initiative in our neighborhood. Your site provided us with valuable information to help us get started|.You have done a great job!
Thanks for the informative article. My wife’s calling me for dinner So I need to run off without reading as much as I’d like. But I put your blog on my RSS feed so that I can read more.
Good info. I reached on your website by accident, so thanks.
We stumbled over here by a different web address and thought I might check things out. I like what I see so now i’m following you. Look forward to looking into your web page yet again.
I would like to find a weblog the place i will just type any situation that pertains to intellect. Kind of like your log but is not for the reason that personal. Good quality sites when I can get started our web log 100 % free and additionally where by most people notice???? Satisfy along with considerably thank you preferred!!:).