Hi!
I need to write a row at a time or a whole sheet at a time, anything
faster than one cell at a time in Excel sheet using Win32::OLE. Can
anyone help me?
Spreadsheet::WriteExcel module have functions for writing row at a
time but I need to modify existing Excel file and the module does not
allow that.
Thank you in advance!
Hey,
You must look for the package Spreadsheet::WriteExcel
With this package you can create an Excel document realy fast.
With the Perl listing below I create an Excel file first and then I
write data in it based on an sql statement.
In this example I did use an connection to an Access database.
Have fun.
#!perl/bin/perl
use Spreadsheet::WriteExcel;
use DBI;
# Create a new Excel workbook called perl.xls
my $excel_file = $ent2 -> get();
my $workbook = Spreadsheet::WriteExcel->new($excel_file);
my $worksheet = $workbook->addworksheet();
$sqlstatement9= $txt1->get('0.0','end');
#open connection to Access database
$dbh9 = DBI->connect('dbi:ODBC:driver=microsoft access driver
(*.mdb);dbq=C:\dump9\MS_Access.mdb');
#prepare and execute SQL statement
$sth9 = $dbh9->prepare($sqlstatement9);
$sth9->execute ||
die "Could not execute SQL statement ... maybe invalid?";
my $i=0;
#output database results
while (@row=$sth9->fetchrow_array())
{
$worksheet->write($i, 0, @row[0]);
$worksheet->write($i, 1, @row[1]);
$worksheet->write($i, 2, @row[2]);
$worksheet->write($i, 3, @row[3]);
$worksheet->write($i, 4, @row[4]);
$worksheet->write($i, 5, @row[5]);
$worksheet->write($i, 6, @row[6]);
$worksheet->write($i, 7, @row[7]);
$worksheet->write($i, 8, @row[8]);
$worksheet->write($i, 9, @row[9]);
$worksheet->write($i, 10, @row[10]);
$worksheet->write($i, 11, @row[11]);
$worksheet->write($i, 12, @row[12]);
$worksheet->write($i, 13, @row[13]);
$worksheet->write($i, 14, @row[14]);
$worksheet->write($i, 15, @row[15]);
$worksheet->write($i, 16, @row[16]);
$worksheet->write($i, 17, @row[17]);
$worksheet->write($i, 18, @row[18]);
$worksheet->write($i, 19, @row[19]);
$worksheet->write($i, 20, @row[20]);
$worksheet->write($i, 21, @row[21]);
$worksheet->write($i, 22, @row[22]);
$worksheet->write($i, 23, @row[23]);
$worksheet->write($i, 24, @row[24]);
$worksheet->write($i, 25, @row[25]);
$worksheet->write($i, 26, @row[26]);
$worksheet->write($i, 27, @row[27]);
$worksheet->write($i, 28, @row[28]);
$worksheet->write($i, 29, @row[29]);
$worksheet->write($i, 30, @row[30]);
$i=$i+1;
};