How can I modify an existing Excel workbook with Perl?

perl, spreadsheet, xls

Solution

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.

Problem

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.

Original source