dhoss you don't appear to have made any progress since last we talk about this, ooh, 12 hours ago? (You had put roughly the same code on your scratchpad.)

Like I told you then: "You can't just make shit up and expect Perl (or in this case, Template::Toolkit) to know what you mean." You're opening an Excel file, taking a reference to a worksheet, and feed it directly to Template::Toolkit, and expect it to extract what it needs, which I assume to be an AoH. (Actually it's worse still, you're passing a dereferenced (as an array) reference to the worksheet, hence, a list, not a single item.)

So I did the experiment, I replaced the reference to the worksheet with an array of hashes, and ran the code. And I do end up with an XML file I expected to end up with.

In order not to duplicate the effort, here's my sample code:

## process the template print "Converting...\n\n"; print "Writing to file...\n\n"; $xmlfile->process( $xmltemplate, { xml => [ { id => 'ID1', category => 'CATEGORY1', code => 'CODE1', title => 'TITLE1', group => 'GROUP', sub_group => 'SUB-GROUP1', sequence => 'SEQUENCE1', role_mandatory => 'ROLE-MANDATORY1', role_recommended => 'ROLE-RECOMMENDED1', role_optional => 'ROLE-OPTIONAL1', url => 'URL1', modality => 'MODALITY1', length => 'LENGTH1', }, { id => 'ID2', category => 'CATEGORY2', code => 'CODE2', title => 'TITLE2', group => 'GROUP', sub_group => 'SUB-GROUP2', sequence => 'SEQUENCE2', role_mandatory => 'ROLE-MANDATORY2', role_recommended => 'ROLE-RECOMMENDED2', role_optional => 'ROLE-OPTIONAL2', url => 'URL2', modality => 'MODALITY2', length => 'LENGTH2', } ] },

So that's apparently the format TT2 expects. "All" you still have to do, is actually extract the data out of the Excel file, and turn it into a proper AoH. The "old code" you linked to should work as a good source, you most likely have to process the file row by row, producing a hash per row, and the hash keys should be derived from the column names, either out of the headers (likely row 0, if present), or be hardcoded based on the column number. The cell contents will become the value in the hash.

Maybe there are easier ways, it could be that the AnyData/DBD::AnyData family of file readers could let you treat the spreadsheet as a database. Does it not? Or else, ODBC surely must be capable of it.

p.s. Did you think of XML-escaping the strings? I haven't looked, but somehow, I doubt it...
update I see that you haven't. Well, it may be a finishing touch, but still, it needs to be handled eventually, in order to get a solid product.


In reply to Re: Excel to XML issue with Spreadsheet::ParseExcel by bart
in thread Excel to XML issue with Spreadsheet::ParseExcel by stonecolddevin

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.