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

Hi Team, I am new to Perl. I recently installed perl (5.10) in my unix box with some modules. I have a requirement, I need to open an existing excel sheet and add some rows to it.. and then add chart to this sheet.. i had succeded till adding data to the existing excel.. but i am not able to add chart to this existing excel... i tried all google items.. still no progress... i ma not even sure, that perl can do this or not.. please help me with sample code to add chart to existing excel sheet... i am updating here with the same stack overflow thread.. http://stackoverflow.com/questions/34044014/add-chart-to-an-existing-excel-using-perl/34044802?noredirect=1#comment55873899_34044802

Replies are listed 'Best First'.
Re: perl help
by choroba (Cardinal) on Dec 08, 2015 at 13:56 UTC
    Is this StackOverflow post related? If so, you could have provided more info. If not, you can gain information from there.
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Yes.. its me who started that thread in stack overflow.. but there was no gain..
Re: perl help
by ww (Archbishop) on Dec 08, 2015 at 14:02 UTC

    Perl can indeed "add some rows" (albeit not quite as you may imagine, since writing to an existing file -- esp. Excel, can be problematic). Try searching cpan.org (or your unix distos pre-packaged add-ons if it offers them) for "Excel."

    As to "sample code" however... well, that's just not the way things work here. This is not a code-writing service, but, rather, a site where many will help you learn if you show a desire to do so. And the best way to do that is to update your question to show

    • what you've tried
    • how that fails to satisfy you
      ...and
    • any warnings or errors Perl offers to help you solve your problem.

    And just BTW, even if 5.10 is the latest your unix can offer, you'll want to be aware that there are significant changes and enhancements in more recent versions, particularly those released since 5.16.


    Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:

    1. code
    2. verbatim error and/or warning messages
    3. a coherent explanation of what "doesn't work actually means.
      use Spreadsheet::ParseExcel; use Spreadsheet::ParseExcel::SaveParser; use Spreadsheet::WriteExcel; # Open an existing file with SaveParser my $parser = Spreadsheet::ParseExcel::SaveParser->new(); my $template = $parser->Parse('MyExcel.xls'); my $worksheet = $template->worksheet('Firstsheet'); my $chart = $template->add_chart( type => 'line' ); $chart->add_series( categories => '=URV!$A$17:$A$442', values => '=URV!$D$17:$D$442', name => 'pended graph', );
      This is what i tried... here i am opening an already existing excel sheet (MyExcel.xls) going to its first sheet (Firstsheet) and then adding a chart to it.... error: Can't call method "add_chart" on an undefined value at charts4.ps line 20 my perl version : This is perl 5, version 22, subversion 0 (v5.22.0) built for aix I am expecting a chart displayed with the existing data in the existing excel.. i know charts work when we use my $workbook = Spreadsheet::WriteExcel->new( 'chart_column.xls' );... but i dont want to create a new excel sheet.. i want - open my existing excelsheet and the add chart to this already existing excel sheet.. Thanks in advance!

        " ... i want - open my existing excelsheet ....

        And I want a pony.

        But, as explained in the first (and so far, only) answer to your StackOverflow post, if Santa (or, more likely, the Grinch) brings you the pony you're asking for it will be (at best) a bucking, unbroken and untrustworthy bronco. You don't really want to have to ride that one.

        And please, when you post, read the formatting instructions at the text-entry box! CODE TAGS! <c> code here </c>


        Come, let us reason together: Spirit of the Monastery

        I find this error message highly suspect. You claim that the above is (part of) the code you run, but there is very little chance that the call to ->worksheet() succeeds while the call to ->add_chart fails due to $template not being defined.

        Please post a short, self-contained example so that we can replicate your problem.