Ah, the joys of having code to look at. You're going to a lot of trouble to generate the CSV, when Excel will do it for you automatically.
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;
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:
1,2,3,4 2,"Who, What?",4,5 3,4,5,6 4,5,6,7
Update:
If, despite this, you really need to get rid of commas, the following code will remove commas from text:
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 => ""});
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.
End of update

Regards,

John Davies

In reply to Re^3: Win32::OLE Excel search and replace commas by davies
in thread Win32::OLE Excel search and replace commas by generator

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.