473,387 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Can i convert MySQL db records into microsoft word documents?

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
6 8610
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Zak Chababe | last post by:
Hi, We are in the process of converting thousands of MS word documents into some sort of database files like sql or comma separated files. Is there something out there with Perl that allows me to...
2
by: David | last post by:
Using the article from this link, http://www.codeproject.com/aspnet/wordapplication.asp, I have been playing with generating Word documents using an ASP.NET application. The only short coming...
1
by: John | last post by:
Hi I have a feature to open word documents from my vb.net app. Is it possible that when a user saves a word document, my vb.net app gets the name under which the document is saved and the date...
5
by: Mark Jerde | last post by:
Sorry if these are the wrong newsgroups -- so many to choose from! The first draft of a Word document is about 200 pages. The second draft is about 275 pages. I am required to produce a 3rd...
7
by: Dave | last post by:
Apologies for the newbie question. I have created a vb.net program for my company that is designed to work with Word Templates (about forty of them that we commonly use) that are selected by the...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
1
by: corcoranj | last post by:
Hello everyone, I have a series of Microsoft word documents, gathered via a SQL query. I would like to be able to print these documents, no matter the number to the clients computer. I have tried...
20
MMcCarthy
by: MMcCarthy | last post by:
This problem was proposed to me but not really my area of expertise so I thought I would open it up to the forum to see if anyone had any bright ideas. The problem is generating Microsoft Word...
0
by: pgill | last post by:
I have approximately 5,000 Microsoft Word Documents stored in a folder on my c drive and saved by a case number. This case number is also a primary key in my SQL Server 2005 database. Can I do a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.