Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-18 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found