Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Slow Excel access via Win32::OLE

by Unanimous Monk (Sexton)
on Apr 26, 2006 at 19:39 UTC ( [id://545857]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://545857]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-04-25 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found