2013年11月11日 星期一

Perl read / write Excel file

Reference:
http://blog.dwightmann.com/entry.asp?id=60
http://stackoverflow.com/questions/9761443/issues-reading-time-value-in-perl-using-win32ole

use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';

$Win32::OLE::Warn = 3; # die on errors...

$excel_file = "c:/tmp/myexcel.xls";

my $Excel_to_read = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');
my $Book_to_read = $Excel_to_read->Workbooks->Open($excel_file);
my $Sheet_to_read = $Book_to_read->Worksheets(1);

print $Sheet_to_read->Cells(5,3)->{'Value'};

註:針對欄位格式為自訂,必須用$Sheet_to_read->Cells(5,3)->{'Text'}

沒有留言:

張貼留言