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


In reply to Re: Merge Excel data with Word Template by blindluke
in thread Merge Excel data with Word Template by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.