in reply to Re: Win32::OLE Excel search and replace commas
in thread Win32::OLE Excel search and replace commas
I did, however, find a solution. I extracted the cell values then ran a substitute =~ s/,//; on the scalar value before writing it to a text file, followed by a comma.
#!c:/perl/bin/perl.exe use strict; use warnings; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; open (OUTPUT,">>","c:/assess/output.txt"); my $Excel = Win32::OLE->GetActiveObject ('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); my $Book = $Excel->Workbooks->Open ("C:/assess/assessment.xls"); my $Sheet = $Book->Worksheets(1); my $LastRow = $Sheet->UsedRange->Find({What=>"*", SearchDirection=>xlPrevious, SearchOrder=>xlByRows})->{Row}; my $array = $Sheet->Range("B2:"."F".$LastRow)->{'Value'}; foreach my $ref_array (@$array) { foreach my $scalar (@$ref_array) { $scalar =~ s/,//; print OUTPUT "$scalar,"; } print OUTPUT "\n"; } $Book->Close;
Your warning regarding the use of commas in formulas was wise but in this case irrelevant. The subsequent processing used only integer values associated with unit cost, unit rate and account code (text string). All fields with formulas are ignored.
Thanks again for taking the time to reply. It ain't pretty but it will do the job.
generator
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Win32::OLE Excel search and replace commas
by davies (Monsignor) on Oct 12, 2010 at 06:56 UTC | |
by generator (Pilgrim) on Nov 08, 2010 at 04:41 UTC | |
by davies (Monsignor) on Nov 08, 2010 at 13:25 UTC | |
by generator (Pilgrim) on Nov 14, 2010 at 02:51 UTC |