|
Posted by malatestapunk on 12/05/06 05:55
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
Navigation:
[Reply to this message]
|