I've got no problems using Spreadsheet::WriteExcel it's a easy, wonderful module. However, it cannot write to an already exisiting Excel file. So I installed Spreadsheet::ParseExcel however I, for the life of me, do not understand how can I open up an existing .xls and then modify it. I did read Spreadsheet::ParseExcel's docs, however I just don't understand them, he doesn't provide an example on how to do this. Here's my current code.. Please help.
#!/usr/bin/perl use Spreadsheet::WriteExcel; use Spreadsheet::ParseExcel; my $oExcel = new Spreadsheet::ParseExcel; my $weekday = (Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturda +y)[(localtime)[6]-1] ; my $dayofmonth = (localtime)[3] - 1; my $month = (January, February, March, April, May, June, July, August, + September, October, November, December)[(localtime)[4]]; my $date = (localtime)[3] - 1; my $column = (localtime)[6] + 1; my $row = 2 + $dayofmonth; my $excelrow = $row + 1; my $aolstats; my $msnstats; my $wwwstats; my $aolfile = "/stats/aol"; my $msnfile = "/stats/msn"; my $wwwfile = "/stats/www"; ######################### # Get the stats ######################### open(AOLFILE, $aolfile) or die "Couldn't open AOL stats: $!\n"; $aolstats = <AOLFILE>; if ($aolstats =~ /\d{4}-\d{2}-\d{2}-aol\s+(.*)/) { $aolstats = $1; } open(MSNFILE, $msnfile) or die "Couldn't open MSN stats: $!\n"; $msnstats = <MSNFILE>; if ($msnstats =~ /\d{4}-\d{2}-\d{2}-msn\s+(.*)/) { $msnstats = $1; } open(WWWFILE, $wwwfile) or die "Couldn't open WWW stats: $!\n"; $wwwstats = <WWWFILE>; if ($wwwstats =~ /\d{4}-\d{2}-\d{2}-www\s+(.*)/) { $wwwstats = $1; } ################################ # Get rid of the comma in stats ################################ if ($aolstats =~ /(\d+),(\d+)/) { $aolstats = $1 . $2; } if ($msnstats =~ /(\d+),(\d+)/) { $msnstats = $1 . $2; } if ($wwwstats =~ /(\d+),(\d+)/) { $wwwstats = $1 . $2; } ################################ # Create the worksheets ################################ my $workbook = $oExcel->Parse('test2.xls'); #this is what i tried, doe +snt work #my $workbook = Spreadsheet::WriteExcel->new("test2.xls"); my $worksheet1 = $workbook->addworksheet('1st Quarter 2002'); my $worksheet2 = $workbook->addworksheet('2nd Quarter 2002'); my $worksheet3 = $workbook->addworksheet('3rd Quarter 2002'); my $worksheet4 = $workbook->addworksheet('4th Quarter 2002'); my $worksheet5 = $workbook->addworksheet('Daily Traffic 4th Quarter'); $worksheet3->activate(); # Worksheet that you see when you open up t +ext2.xls my $format = $workbook->addformat(); $format->set_bold(); $worksheet3->write(0, 0, "KATRILLION TRAFFIC 3rd QUARTER JULY-AUGUST-S +EPTEMBER", $format); $worksheet3->write(2, 0, 'Date', $format); $worksheet3->write(2, 1, 'Day', $format); $worksheet3->write(2, 2, 'AOL', $format); $worksheet3->write(2, 3, 'MSN', $format); $worksheet3->write(2, 4, 'Katrillion', $format); $worksheet3->write(2, 5, 'CS', $format); $worksheet3->write(2, 6, 'Daily Total', $format); $worksheet3->write(2, 7, 'AOL Weekly', $format); $worksheet3->write(2, 8, 'Mo. Run Total', $format); $worksheet3->write(2, 9, '% change', $format); $worksheet3->write($row, 0, "$month $date"); $worksheet3->write($row, 1, $weekday); $worksheet3->write($row, 2, $aolstats); $worksheet3->write($row, 3, $msnstats); $worksheet3->write($row, 4, $wwwstats); $worksheet3->write_formula($row, 6, "=SUM(C$excelrow:F$excelrow)" );

In reply to Need help with opening up a Excel file then modifying it. by vxp

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.