in reply to Re^2: Win32::OLE Excel search and replace commas
in thread Win32::OLE Excel search and replace commas
A few points. First, indenting code within if blocks, loops etc. will make it easier for you to understand what your code is doing in a few months' time. Second, I commented in Re^3: Win32::Ole excel external data range on both with and relying on an existing instance of Excel. I suspect both you and the other OP copied code from the same place. Third, the thread I mentioned earlier describes dealing with embedded commas and quotes, but the general rule for CSVs is that you can embed a comma in quotes. The output of my test file is:use strict; use warnings; use Win32::OLE; my $Excel=Win32::OLE->new('Excel.Application'); $Excel->{Visible}=1; $Excel->{DisplayAlerts}=0; my $Book = $Excel->Workbooks->Open("F:\\assess\\assessment.xls") or di +e "Can't open file"; $Book->SaveAs({Filename => "F:\\Assess\\Assessment.csv", FileFormat => 6, #xlCSV, CreateBackup => 0}); $Excel->Quit;
Update:1,2,3,4 2,"Who, What?",4,5 3,4,5,6 4,5,6,7
This won't get rid of formatting commas in numbers. To do that, you will need to change the formats. But from your code, you're looking at the underlying numbers anyway, rather than printing a file.use strict; use warnings; use Win32::OLE; my $Excel=Win32::OLE->new('Excel.Application'); $Excel->{Visible}=1; my $Book = $Excel->Workbooks->Open("F:\\assess\\Lorem.xls") or die "Ca +n't open file"; $Excel->Cells->Replace({ What => ",", Replacement => ""});
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Win32::OLE Excel search and replace commas
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 |