By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,960 Members | 1,009 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,960 IT Pros & Developers. It's quick & easy.

Can i convert MySQL db records into microsoft word documents?

P: n/a
Hi all, i need some help over here... 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?

FYI, the database records are obtained by end users submitting the
forms themselve and i saved it in my db...

Thanx.

Regards,
Justin

Dec 4 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
NC
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

Dec 4 '06 #2

P: n/a
Justin <ju****@smsit.com.mywrote:
Hi all, i need some help over here... 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?

FYI, the database records are obtained by end users submitting the
forms themselve and i saved it in my db...
There are zillion solutions for this:

You could for instance present the mysql data as a table in a web
page. Word can import from a web page.

Or:

You could install the Mysql odbc connector for Windows and extract the
data directly into Word (don't actually know if this is possible,
possibly you would have to use Excel for this - but then again:
it's easier to convert from Excel to Word than from cvs to Word)

Peter

--
http://www.boosten.org

Mail: peter at boosten dot org
Dec 4 '06 #3

P: n/a
NC wrote:
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.
Actually, it can be done *much* easier than that.
Just rename the .CSV file as to a .DOC extension.
When the Windows users dl it, it'll load up in Word... and it'll look
*good*.

You *might* have to specify the mime type on the page just to make
sure... but that's all.

Dec 4 '06 #4

P: n/a
Thanx all of ya.... Btw, NC, im trying out on ur solutions... hopefully
can get it done... im using a linux server... so the generating rtf
files surely is a much more attractive solution... =>

NC wrote:
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
Dec 5 '06 #5

P: n/a
Actually, you can do RTFs the quick and dirty way in any server
environment.

First you make a RTF template in any editor (Word, AbiWord, OO Writer,
whatever). You format it as you would normally do, and you use some
identifiers in places where you want your database data to appear (e.g.
_USER_NAME_, _USER_BIRTHDAY_, whatever). It is important that you save
it as RTF. Then you upload that template to a place your PHP script can
reach.

Of course, if you're very fluent in RTF formating, you could just open
up a plain text editor and code everything yourself ;)

Then you modify your script to open up the template yuo just made and
preg_replace all identifiers with corresponding data. And that's it -
send content-type and content-disposition headers and just echo your
template.

This is obviously a very simple example, but you could make it much
more interesting by introducing some sort of templating engine for your
RTFs. I used this approach with POP (plain old php) templates, and it
worked fine.

Justin wrote:
Thanx all of ya.... Btw, NC, im trying out on ur solutions... hopefully
can get it done... im using a linux server... so the generating rtf
files surely is a much more attractive solution... =>

NC wrote:
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
Dec 5 '06 #6

P: n/a
I should have read ALL posts before I replied ... Sorry for duplicating
the NCs solution.

Justin wrote:
Thanx all of ya.... Btw, NC, im trying out on ur solutions... hopefully
can get it done... im using a linux server... so the generating rtf
files surely is a much more attractive solution... =>

NC wrote:
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
Dec 5 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.