in reply to Slow Excel access via Win32::OLE

It will be much faster if you copy the whole array into Excel at once. It may be faster to use one of the other solutions provided above or to create a .csv file, but copying the whole array at once should be around 10x faster than looping through each cell.

Also, see code below for formatting bold, italic, and color.

use strict; use Win32::OLE; my $rowCount = 10000; my $colCount = 10; print "Build array\n"; my @data; for my $row (0..$rowCount) { for my $col (0..$colCount) { $data[$row][$col] = "Row: $row, Col: $col"; }; }; print "Open Excel\n"; my $app = Win32::OLE->new('Excel.Application'); my $book = $app->Workbooks->Add; my $sheet = $book-> Worksheets->Add; my $cell = $sheet->Range('A1'); $app->{Visible} = 1; print "Copy array to Excel\n"; $sheet->Range($cell, $cell->offset($rowCount, $colCount))->{Value} = \ +@data; print "Format\n"; my $red = 0x0000FF; my $green = 0x00FF00; my $blue = 0xFF0000; my $yellow = 0x00FFFF; $cell->EntireColumn->Font->{Bold} = 1; $cell->EntireColumn->Font->{Italic} = 1; $cell->EntireColumn->Interior->{Color} = $yellow;

Replies are listed 'Best First'.
Re^2: Slow Excel access via Win32::OLE
by josephjohn (Acolyte) on May 19, 2006 at 03:29 UTC
    Hi Unanimous,
    Thanks a lot for the new method. It works great. I should say the data transfer speed is more than 10x. It saved my work.
    Thanks to others for suggestions on WriteExcel. I kept away from it as i've heard that existing excel files cannot be worked on with that module.
    Joseph.