You are here: Re: Can i convert MySQL db records into microsoft word documents? « PHP Programming Language « IT news, forums, messages
Re: Can i convert MySQL db records into microsoft word documents?

Posted by NC on 12/04/06 19:46

Justin wrote:
>
> i found the solution to export file from mysql db into *.csv.
> but is there anyway to convert the contents into *.doc and
> save in my webserver and providing a link for the end users
> to download the word file?

Yes. You need a dedicated Windows server with Word installed
on it. You would retrieve records from the database and convert
them into Word documents by calling Word as a COM object.
The disadvantage of this approach is that it's expensive, both
in terms of system resources utiltized and in terms of direct
monetary costs (dedicated Windows servers are not particularly
cheap).

A much more attractive alternative is to generate RTF (Rich Text
Format) files. Word understands them just fine, as do most of
other modern word processors. Here's a simple example.

Create an empty document in Word and type:

First Name: ###First_Name###
Last Name: ###Last_Name###

Then save this document as a Rich Text Format (RTF) file.
Let's call it app.rtf. Put this file on your server next to your
script. Now you can do this:

<?php // be sure this is the first line of the script file

$first = 'John';
$last = 'Doe';
$rtf = file_get_contents('app.rtf');
$rtf = str_replace('###First_Name###', $first, $rtf);
$rtf = str_replace('###Last_Name###', $last, $rtf);
header ('Content-type: application/msword');
// alternatively, you may try
// header ('Content-type: application/rtf');
header ('Content-Disposition: inline; filename: jobapp.rtf');
echo $rtf;
die ();

?>

And the user will see a Word document that says:

First Name: John
Last Name: Doe

This is a very simple example, but you can make it as complicated
as you want, with as many placeholders as you need. In your case,
you will need to draw $first and $last from the database.

Cheers,
NC

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация