Ok i came acroos this thread because i wanted to edit an existing xlsx file. I jumped directly onto Excel::Writer::XLSX as is the new standard to write xlsx files. After some misleading errors i read in the docs of the module:
This module cannot, as yet, be used to write to an existing Excel XLSX file.

Ouch! when i realized was not possible i choosed that writing to an existing xls (old format file) would suffice for my tests and i ended with the following code. A mix of Spreadsheet::ParseExcel::SaveParser and Spreadsheet::WriteExcel worked out fine. I put it here for future memory.

use strict; use warnings; use Spreadsheet::ParseExcel::SaveParser; use Spreadsheet::WriteExcel; # check for right parameters my ($file,$howlong,$sleep) = @ARGV; unless ( defined $file && $file =~/.+\.xls/ && defined $howlong && $howlong =~/^\d+$/ && defined $sleep && $sleep =~/^\d+$/){ die "USAGE: $0 filename.xls minutes_of_duration sleep_seconds", "\n\n\t$0 file.xls 5 1\n\n", "will creates file.xls and each seconds writes to it, for 5 m +inutes.\n"; } $howlong *=60; $howlong = $^T+$howlong; print "\tNB: $0 will run until ",scalar localtime($howlong),"\n"; my ($col,$row); $col = $row = 0; # initialize ta new XLS file my $workbook_init = Spreadsheet::WriteExcel->new($file); my $worksheet_init = $workbook_init->add_worksheet(); $worksheet_init->write( $row, $col, "XLS initialized at ".scalar local +time(time)); $workbook_init->close(); $row++; # modify the same xls in the while loop while (time <= $howlong){ print "writing row $row\n"; my $parser = Spreadsheet::ParseExcel::SaveParser->new(); my $template = $parser->Parse($file); my $worksheet = $template->worksheet(0); $worksheet->AddCell( $row, $col, scalar localtime (time) ); $template->SaveAs($file); ++$row; sleep $sleep; } print "\treached ",(scalar localtime(time)),"\n\tscheduled termination +"

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: Excel how to open existing worksheet -- create and append to an XLS file by Discipulus
in thread Excel how to open existing worksheet by AtlasFlame

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.