excel - delete a worksheet of a workbook using perl -
hi need delete worksheet named 'summary' if exists in excel workbook using perl. first parse content of excel file as:
my $parser = new spreadsheet::parseexcel::saveparser; $template = $parser->parse($filename) or die "$!\n"; $workbook = $template->saveas($filename);
now if file had 'summary' worksheet need delete it. can't use spreadsheet::simpleexcel
because file opened object of spreadsheet::writeexcel
/ spreadsheet::parseexcel
, handler hasn't closed file yet. hence can't create new object of spreadsheet::simpleexcel
, point excel , remove worksheet.
is there way delete worksheet. can remove worksheet before save workbook shown in code above.
please try this,
foreach $sheet (@{$template->{worksheet}}){
if($sheet->{name} eq "summary"){ splice(@{$template->{worksheet}},$sheet,1); }
}
Comments
Post a Comment