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!!:).
thanx for image full path suggestion
I genuinely enjoy examining on this internet site , it has wonderful content . “The longing to produce great inspirations didn’t produce anything but more longing.” by Sophie Kerr.
I believe what you posted made a bunch of sense. But, consider this, suppose you added a little content? I ain’t suggesting your information isn’t good, but suppose you added a headline to possibly get people’s attention? I mean Generating microsoft office documents (word, excel) on your webserver using php | Cosninix is a little vanilla. You could look at Yahoo’s front page and watch how they create post headlines to get viewers to click. You might try adding a video or a related pic or two to get people excited about what you’ve written. Just my opinion, it could make your blog a little livelier.
You could certainly see your skills in the paintings you write. The world hopes for more passionate writers such as you who are not afraid to say how they believe. All the time go after your heart. “If you feel yourself falling, let go and glide.” by Steffen Francisco.
I hope you never ever put a stop to! This can be among the top blogs Ive ever before read. Youve got some mad talent right here, man. I just hope you dont shed your type given that youre without a doubt one of many coolest bloggers to choose from. Be sure to preserve it up as the internet demands a person such as you spreading the word.
I believe this is among the so much important information for me. And i am happy studying your article. However should remark on some general issues, The site taste is wonderful, the articles is truly great : D. Good activity, cheers
I feel 1 of your advertisements triggered my browser to resize, you could would like to place that in your blacklist.
Spot on as per usual. Yet another good article!
hello net master, your weblog pagea€?s themes is striking mixed with supporting executing it. Any composes seem to be amazing. Make certain to maintain pace the very good give superior benefits. Meets.
It’s appropriate time to make a few plans for the longer term and it is time to be happy. I have read this submit and if I may I wish to recommend you few fascinating things or tips. Perhaps you can write subsequent articles referring to this article. I desire to read more things approximately it!