T
Tom Niesytto
Howdy - I am using Win32::OLE to create a spreasheet from data.
Spreadsheet is fairly big (2000 rows x 30 columns) and cells contain
embedded newlines (if itwas not for that I would simbly import tab
delimited file).
To write to Excel spreadsheet I do sth like:
-----------------------------------------
sub write_array_as_excel_file
{
my $output_file = shift;
my $array_ref = shift; #reference to array of references to arrays
eval{$excel = Win32::OLE->GetActiveObject('Excel.Application')};
die "Excel not installed" if $@;
unless (defined $excel) {
$excel = Win32::OLE->new('Excel.Application', 'Quit')
or die "Oops, cannot start Excel";
}
#to avoid excessive dialogs when saving in non-Excel format
$excel->{DisplayAlerts} = 0;
# get a new workbook
my $wbook = $excel->Workbooks->Add
|| print STDERR "didnt add new workbook: $!\n";
# write to a particular cell
my $wsheet = $wbook->Worksheets(1);
my $ref;
my $cell_value;
my $row_num = 0;
my $col_num = 0;
foreach $ref (@{$array_ref}) {
$row_num++;
$col_num = 0;
foreach $cell_value (@{$ref}){
$col_num++;
$wsheet->Cells($row_num,$col_num)->{Value} = "$cell_value";
}
}
$wbook->SaveAs($fullname_output_file);
undef $wbook;
}
-----------------------------
Problem is - it is slow.
Takes about 20 mins to write out the output.
What am I doing wrong here?
Thanks for any pointers,
JT
Spreadsheet is fairly big (2000 rows x 30 columns) and cells contain
embedded newlines (if itwas not for that I would simbly import tab
delimited file).
To write to Excel spreadsheet I do sth like:
-----------------------------------------
sub write_array_as_excel_file
{
my $output_file = shift;
my $array_ref = shift; #reference to array of references to arrays
eval{$excel = Win32::OLE->GetActiveObject('Excel.Application')};
die "Excel not installed" if $@;
unless (defined $excel) {
$excel = Win32::OLE->new('Excel.Application', 'Quit')
or die "Oops, cannot start Excel";
}
#to avoid excessive dialogs when saving in non-Excel format
$excel->{DisplayAlerts} = 0;
# get a new workbook
my $wbook = $excel->Workbooks->Add
|| print STDERR "didnt add new workbook: $!\n";
# write to a particular cell
my $wsheet = $wbook->Worksheets(1);
my $ref;
my $cell_value;
my $row_num = 0;
my $col_num = 0;
foreach $ref (@{$array_ref}) {
$row_num++;
$col_num = 0;
foreach $cell_value (@{$ref}){
$col_num++;
$wsheet->Cells($row_num,$col_num)->{Value} = "$cell_value";
}
}
$wbook->SaveAs($fullname_output_file);
undef $wbook;
}
-----------------------------
Problem is - it is slow.
Takes about 20 mins to write out the output.
What am I doing wrong here?
Thanks for any pointers,
JT