Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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 ( #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
Node Status?
node history
Node Type: note [id://1108071]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2021-04-15 01:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?