Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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);
Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://722716]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (13)
As of 2016-12-05 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (86 votes). Check out past polls.