Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I modify an existing Excel workbook with Perl?

With Spreadsheet::WriteExcel, I can create a new workbook, but what if I want to open an existing book and modify certain columns? How would I accomplish that?

I could parse all of the data out of the sheet using Spreadsheet::ParseExcel then write it back with new values in certain rows/columns using Spreadsheet::WriteExcel, however. Is there a module that already combines the two?

Mainly I just want to open a .xls, overwrite certain rows/columns, and save it.

like image 956
user105033 Avatar asked Sep 02 '09 17:09

user105033


1 Answers

Spreadsheet::ParseExcel will read in existing excel files:

my $parser   = Spreadsheet::ParseExcel->new();
# $workbook is a Spreadsheet::ParseExcel::Workbook object
my $workbook = $parser->Parse('Book1.xls');

But what you really want is Spreadsheet::ParseExcel::SaveParser, which is a combination of Spreadsheet::ParseExcel and Spreadsheet::WriteExcel. There is an example near the bottom of the documentation.

like image 121
Ether Avatar answered Sep 22 '22 19:09

Ether