Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I need some guidance on how to go about merging some Excel data saved as a tab delimited file into a Word template using Perl. I don't want anyone to code it for me, just give me a shove in the right direction, such as what modules I need to use and maybe a few snippets of code to put me on the right track. I am very inexperienced with Perl so this will be a real learning experience for me.

The plus is if I do a good job with this project it may result in gainful employment as a junior programmer so any assistance would be greatly appreciated.

Thanks in advance,

Carl

Replies are listed 'Best First'.
Re: Merge Excel data with Word Template
by thanos1983 (Parson) on Aug 10, 2014 at 23:50 UTC

    Hello Anonymous Monk,

    I have never done this before so I can not really tell you how to do extract the data from a word file and process them.

    But recently another question was similar to yours, not exactly but similar. Where I created a short script of exporting nth excel files, convert them, combine them and store them to '*.csv' file. At that point you can easily convert them back to excel or word. I guess about Word I do not know. More information can be found at writing after parsing. I think this a good starting point to see how the process can be done.

    But I am curious why you are not using Google first to check what information you can found and continue from there.

    With a really quick search I found Win32::Word::Writer, Text::Extract::Word etc...etc...

    But is also depends on what operating system you are using? (Windows, Linux, Mac)...The same solution does not apply to all.

    Well I think you currently have more than enough information and questions to start your search. If I was you I would create a sample of code and try a few attempts based on the modules that you can find online. Coding is about searching, testing failing again and again until you make it.

    So go ahead start coding, and when you need some help your code you can ask a question again here.

    I hope my answer provides you with enough information, and links to get you started.

    Seeking for Perl wisdom...on the process of learning...not there...yet!
Re: Merge Excel data with Word Template
by Anonymous Monk on Aug 10, 2014 at 23:26 UTC

    I don't want anyone to code it for me, just give me a shove in the right direction, such as what modules I need to use and maybe a few snippets of code to put me on the right track.

    You can find that by searching, like Win32/OLE related tutorials/examples/resources

Re: Merge Excel data with Word Template
by blindluke (Hermit) on Aug 11, 2014 at 10:33 UTC

    My suggestions are based on the assumption, that your "Word template" is simple enough to recreate (for example, you are required to merge your Excel output into a .doc file with some header, footer and basic table formatting).

    Excel data saved as a tab delimited file is just a tab delimited file. So, don't focus on the origin of the data and use Text::CSV to read the file. If the module documentation seems too detailed, here is a nice tutorial.

    Remember to tell the module that you are dealing with tab separated fields:

    my $csv = Text::CSV->new ({sep_char => '\t'});

    When you're done with input, the only thing left is to print the data to a file your Word users can read. I would suggest using RTF::Writer, and saving the RTF file with a .doc (or .docx) extension. Word will open the file without problems, and if you do not need any special formatting, it should be enough.

    Tables in RTF are a bit tricky, but if your needs are simple, the following snippet from the module documentation should help you:

    my $decl = RTF::Writer::TableRowDecl->new('widths' => [1500,1900]) +; $h->row($decl, "Stuff", "Hmmm"); $h->row($decl, [\'\ul', 'Foo'], 'Bar', \'\bullet'); $h->row($decl, "Hooboy.");

    Hopefully, this will be of some use to you. Good luck!

    regards,
    Luke