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;