in reply to inserting parsed results into excel rows and columns in delimited format


If you need to write an array of data or an array of arrays in Excel then it is much more effiecient to write the data as a single Range() rather than writing it cell by cell.

Here is a short example for a single row. Note that you must specify the range in A1 format and that the data must be passed as an array ref.

#!/usr/bin/perl -w use strict; use Cwd; use Win32::OLE; my $application = Win32::OLE->new("Excel.Application"); my $workbook = $application->Workbooks->Add; my $worksheet = $workbook->Worksheets(1); my @data = ('maggie', 'milly', 'molly', 'may'); $worksheet->Range('A1:D1')->{Value} = \@data; $workbook->SaveAs({FileName => cwd() . '/test.xls'}); $workbook->Close;

For a 2D array the above example would change as follows:

my @data = ( ['maggie', 'milly', 'molly', 'may' ], [13, 14, 15, 16 ], ['shell', 'star', 'crab', 'stone'] ); $worksheet->Range('A1:D3')->{Value} = \@data;

For the sake of comparison here is a similar example using Spreadsheet::WriteExcel:

#!/usr/bin/perl -w use strict; use Spreadsheet::WriteExcel; my $workbook = Spreadsheet::WriteExcel->new("test.xls"); my $worksheet = $workbook->add_worksheet(); my @data = ( ['maggie', 'milly', 'molly', 'may' ], [13, 14, 15, 16 ], ['shell', 'star', 'crab', 'stone'] ); $worksheet->write_col('A1', \@data);

--
John.