Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Perl to convert a named workseet from an xlsx workbook with multiple worksheets into a csv file

by Loops (Curate)
on Nov 22, 2014 at 02:12 UTC ( [id://1108071]=note: print w/replies, xml ) Need Help??


in reply to Perl to convert a named workseet from an xlsx workbook with multiple worksheets into a csv file

Looks like Spreadsheet::BasicRead doesn't have the ability to select sheet by name. But it does allow you to select each sheet by number, and then query its name... so:

sub sheetNames { my $xlsx = shift; my %ret; my $sheet = $xlsx->getFirstSheet; while ($sheet) { $ret{$xlsx->currentSheetName} = $xlsx->currentSheetNum; $sheet = $xlsx->getNextSheet; } return %ret; } sub selectSheet { my ($xlsx,$name) = @_; my %available = sheetNames $xlsx; $xlsx->setCurrentSheetNum($available{$name}); }

And then before your csv export code runs, do:

selectSheet $ss2, 'My Great Sheet';

Error checking should be added of course, currently it'll just silently fail if the sheet you choose doesn't actually exist.

  • Comment on Re: Perl to convert a named workseet from an xlsx workbook with multiple worksheets into a csv file
  • Select or Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-19 06:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found