I successfully parsed an xls file using Spreadsheet::ParseExcel::SaveParser and modified it with Spreadsheet::WriteExcel.

However working with xlsx file is a whole different thing. I am trying to figure out how to work with Spreadsheet::XLSX for parsing and how to make it work with Excel::Writer::XLSX. Spreadsheet::ParseExcel::SaveParser has a SaveAs() method that makes it possible to apply Spreadsheet::WriteExcel methods on the parsed xml file, but I don't understand how to make it work with xlsx file

When using Spreadsheet::ParseExcel::SaveParser and Spreadsheet::WriteExcel I can write:

#!/usr/bin/perl -w use strict; use Spreadsheet::ParseExcel; use Spreadsheet::ParseExcel::SaveParser; # Open the template with SaveParser my $parser = new Spreadsheet::ParseExcel::SaveParser; my $template = $parser->Parse('template.xls'); # Rewrite the file or save as a new file $workbook = $template->SaveAs('new.xls'); # Use Spreadsheet::WriteExcel methods my $worksheet = $workbook->sheets(0); $worksheet->write($row+2, $col, "World2"); $workbook->close();

I would like to do the same with xlsx files. therefore I'm trying to use Spreadsheet::XLSX and Excel::Writer::XLSX. Instead of:

my $parser = new Spreadsheet::ParseExcel::SaveParser; my $template = $parser->Parse('template.xls');

I use

my $excel = Spreadsheet::XLSX -> new ('test.xlsx');

Now, after parsing the xlsx file I would like to add some data to it and I don't know how to do it. As you can see above when using Spreadsheet::ParseExcel::SaveParser I used SaveAs() function, but Spreadsheet::XLSX dosn't have a SaveAs() method. So how do I add data to parsed xlsx file?

I could not find an answer to my question in this link: http://search.cpan.org/~dmow/Spreadsheet-XLSX-0.13-withoutworldwriteables/lib/Spreadsheet/XLSX.pm Thanks you for your help :)

In reply to Modifying xlsx file with perl by sogo87

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.