Print the contents of an Excel spreadsheet (Perl)
This code can be found in
Chapter 1 of Windows Server Cookbook
Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.
Find out how to download all of the Perl code from this site.
# Adapted from VBScript code contained in the book:
# "Windows Server Cookbook" by Robbie Allen
# ISBN: 0-596-00633-0
use Win32::OLE;
$Win32::OLE::Warn = 3;
# ------ SCRIPT CONFIGURATION ------
$strExcelPath = 'd:\\data.xls';
$intStartRow = 2;
# ------ END CONFIGURATION ---------
$objExcel = Win32::OLE->new('Excel.Application');
if (Win32::OLE::LastError()) {
print "Excel application not installed.\n";
exit 0;
}
$objExcel->WorkBooks->Open($strExcelPath);
$objSheet = $objExcel->ActiveWorkbook->Worksheets(1);
$intRow = $intStartRow;
while ($objSheet->Cells($intRow, 1)->Value ne '') {
print "Row $intRow\n";
print 'Cell 1: ' . $objSheet->Cells($intRow, 1)->Value, "\n";
print 'Cell 2: ' . $objSheet->Cells($intRow, 2)->Value, "\n";
print 'Cell 3: ' . $objSheet->Cells($intRow, 3)->Value, "\n";
print 'Cell 4: ' . $objSheet->Cells($intRow, 4)->Value, "\n";
$intRow = $intRow + 1;
print "\n";
}
$objExcel->ActiveWorkbook->Close();
$objExcel->Application->Quit();
print "Done\n";
|
This code has been viewed 1809 times.
|
New from the creators of TechTasks.com:
StatSheet.com
|