in reply to Win32::OLE & Excel help
Alternatively, you could try using the Excel worksheet CountIf() function. Here is a small working example:
#!/usr/bin/perl use strict; use warnings; use Win32::OLE; use Win32::OLE::Const 'Microsoft Excel'; my $application = Win32::OLE->new("Excel.Application"); my $workbook = $application->Workbooks->Open("c:/temp/test.xls" +); my $worksheet = $workbook->Worksheets(1); my $range = $worksheet->Range("A1:A8"); my $count = $application->WorksheetFunction->CountIf( $range, "2" +); print $count, "\n"; __END__
As a further alternative you could try using Jon Allen's XLSperl which gives you a commandline application that behaves like perl but works on Excel files. Something like this:
XLSperl -lne 'print if /pattern/ and $COL eq "A"' file.xls
XLSperl used Spreadsheet::ParseExcel which may also be an alternative solution.
* This isn't a general rule. It is usually better if you can call a single method on a Range rather than iterate through the Cells. However, I don't think there is an applicable method that will produce the desired results in this case.
--
John.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Win32::OLE & Excel help
by imrags (Monk) on Jan 15, 2009 at 10:31 UTC |