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

Delete an Excel worksheet

by PFudd (Initiate)
on Nov 10, 2008 at 20:29 UTC ( #722716=snippet: print w/ replies, xml ) Need Help??

Description: My input Excel file has four worksheets; I wanted to delete worksheet #2 and save the spreadsheet. There is no function to delete a worksheet in Spreadsheet::ParseExcel nor SpreadSheet::WriteExcel, as they assume that if you didn't want the sheet, you wouldn't have created it.
#!/usr/bin/perl -w
use strict;
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::SaveParser;
my ($INFILE,$OUTFILE)=("in.xls","out.xls");
my $oExcel = new Spreadsheet::ParseExcel::SaveParser;
my $oBook = $oExcel->Parse($INFILE);

splice(@{$oBook->{Worksheet}},1,1);
$oBook->{SheetCount}--;

$oExcel->SaveAs($oBook, $OUTFILE);
Comment on Delete an Excel worksheet
Download Code

Back to Snippets Section

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2014-12-21 01:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (101 votes), past polls