Perl-Sensitive Sunglasses | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
You say "in Linux", but I assume you mean that you want to create Word documents using Perl, which you happen to be running on Linux. Word document format is, errr, complex. Others have said, "make an RTF and convert", but RTF of course lacks most of the features you probably want. However, OpenOffice format (sxw) is very full-featured. Better, it's very straightforward and not hard to generate using Perl. Word can't read them, but OO can do the conversion. This saves you from having to deal directly with Word format as such. (You get to deal with XML, which is MUCH easier.) In general, here's the process I use for automatically generating documents from Perl:
This could be extended, of course, to automatically generate more than just the text content: it would be trivial to insert images (just copy the image file into your working directory, refer to it in the XML by filename, and zip it right in), but with a little bit of experimentation I'm sure it would not be hard to embed spreadsheets and all sorts of fun stuff. With OO, it's all XML, so automatically generating it from Perl is a breeze. It's not really any harder than writing a CGI script to generate (valid) HTML. The only bummer with this approach is that using OO to do the conversion to Word format is a fairly heavyweight thing in terms of system resources. OO has a substantial memory footprint. You wouldn't want to do this on an old Pentium/90 that you've installed Linux on to use as a web server, for example. (You could generate the OO document on there, but you wouldn't want to run OO on there to do the conversion.) 128MB of RAM is recommended, IIRC, for running OO. Also, you don't mention the frequency or speed with which you need to spit out documents. If this is the kind of thing where you're handling web requests and returning a doc to a remote client, then the overhead of OO's load time will be too great. OTOH if you're generating a report that you want to print to give to your boss, you're going to have to load the document in a word processor anyway (to print it), so nothing lost.
In reply to Re: Create MS Word doc in Linux
by jonadab
|
|