Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Reducing the memory usage of Spreadsheet::ParseExcel

by joeperl (Acolyte)
on Feb 24, 2010 at 18:46 UTC ( [id://825140]=note: print w/replies, xml ) Need Help??


in reply to Reducing the memory usage of Spreadsheet::ParseExcel

hi john
what about the sheet name? how to get it in your approach?

regards,
joe

  • Comment on Re: Reducing the memory usage of Spreadsheet::ParseExcel

Replies are listed 'Best First'.
Re^2: Reducing the memory usage of Spreadsheet::ParseExcel
by jmcnamara (Monsignor) on Feb 25, 2010 at 09:44 UTC

    Once you have access to the $workbook object you can access the worksheet objects and then the sheet name. Something like this:
    sub cell_handler { my $workbook = $_[0]; my $sheet_index = $_[1]; my $row = $_[2]; my $col = $_[3]; my $cell = $_[4]; my $worksheet = $workbook->worksheet($sheet_index); my $sheetname = $worksheet->get_name(); print $sheetname, ": ", $cell->{_Value}, "\n"; }
    See the main Spreadshhet::PraseExcel documentation for more details on these methods.

    In a real world situation you would probably check to see if $sheet_index is the same as a stored previous value and print the sheet name if it isn't.

    One thing to look out for is that the callback will only get called for sheets that contain data. So the sheet name of an empty worksheet wouldn't be printed with the above scheme. If this is a use case that you are interested in then you could also handle it by examining the sheet indices.

    --
    John.

      Hi John,
      I did the same kind of thing before seeing your reply, except that i passed the $workbook,$sheet_index as a argument to another function where i found out the sheet name using the same logic..
      but your approach is the simplest and apt one i was looking for...
      guess i've a knack to complicate simple things.. :)

      Thanks a lot for educating me..

      Regards,
      joe

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://825140]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-24 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found