in reply to Re: Help generating MS Word .doc file from perl
in thread Help generating MS Word .doc file from perl

Krambambuli - I also agree, an rtf would be just fine in my case. I just want to make sure that this process spawns something that will open in Word by default. I'm sure my users can go through the Save As and change it to an actual Word file after they are all done with it. Unfortunately, the code referenced in that page is no longer available. :(

jethro - What I meant was that it would just dynamically generate html which was displayed on screen just like a regular web page. No file was bring created or anything, it just shot back the text I wanted as html. The formatting that I wanted (only referring to extra line breaks) was via html tags. There are no font changes, or anything else. The web page output is as expected. This was only a temporary measure as I knew what I wanted the end result to look like but didn't know how to generate the Save As prompt for the download, and I figured that getting to that point wouldn't require much difference in the code (hoping I'm correct on that!) Although, I do think I get your point. Instead of generating a doc/rtf file to be downloaded, I could just write to the server and provide a link on the html output screen, and the user could just right-click and Save Target As, or click and open it directly, correct? This will be hosted on a web server and all users will have access. (Note: I would actually much prefer to create some sort of souped-up Word document that does all of it internally, but I don't know how to program like that. I do have a good grasp on perl which is why I went this route instead.)

Marshall - I'm assuming you are referring to the same thing as above in writing the file to the web site and providing a link. I might go that route. Just out of curiosity, where would be a good place to go to learn about that Win 32 OLE thing? Just in case I do want to get fancy with it.

Thanks much, all!

  • Comment on Re^2: Help generating MS Word .doc file from perl

Replies are listed 'Best First'.
Re^3: Help generating MS Word .doc file from perl
by Marshall (Canon) on May 21, 2010 at 15:47 UTC
    Do a google on Win32:OLE, one site Win32_Perl_Modules. Would also try the Super Search on Monks and would also pay attention to the Active State site. Basically you will find lots of "stuff", which of that "stuff" is the "best stuff", I can't say! I am confident that it is possible for Perl to control WinWord, but I would not underestimate the complexity of the details involved (see below)

    What I've described is similar to what will happen with say an RTF file that WordPad generated. WinWord can read those things.

    I'm not sure that I understand exactly what you mean by "dynamic". Generation of a .doc file upon a new release of a text file every week is quite a different thing than generating a .doc file that continually changes every second based say upon current weather conditions.

    I have generated fancy reports in WinWord from text files before, but not completely automated. The way I did it was create a Word Macro such that I just had to open the text file in Word, then hit say CTL-R (for report) to run the Word macro and then save the resulting file...3 manual steps...took a minute for me to do. This didn't matter as I had to also prepare a management presentation about what the data meant which took hours!

    Now that I think about it, this worked amazingly well! I had control of the format of the text file and that enabled me to avoid writing any WinWord BASIC macro code at all! I did it all with just keyboard macro recorder and use of a Word template file that I made...Search for X, change font to Y, assign heading numbering, let's change landscape instead of portrait mode, etc.

    If you are with my thinking so far, the idea is to NOT to make a Winword doc "from scratch" using Perl to control Word. Make a template and macros that you need within Word so that you can with just a few key strokes make a fancy looking report from the text input. THEN use Perl to automate those very few commands that you can do easily by hand - it may come down to just opening Word and running a single macro. Avoid all of this detailed WinWord Visual Basic stuff to the maximum extent possible.

    Anyway, that is what my thinking would be as a first approach to a fancy document. But it doesn't sound like you need a "fancy document". WinWord can open a plain text or RTF file and import if the user just clicks that it is "ok" to do that.