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.
|
---|
In Section
Seekers of Perl Wisdom