Hi Perl Monks, I've been knocking myself our for several hours trying to figure this one out but I can't. I'm trying to convert a csv file with several quoted items into any excel format. The quotes are killing everything that I've written. Removing the quotes then running the script gets the formatting wrong because the quoted text or numbers belong together. Here's an example of a piece of the csv file:

"Searched for: San Francisco_Microbiome" "Title","Amount","Phase","Program","Awards Year","Solicitation Year","Small Business Name","Small Business Address","Woman Owned","Principal Investigator Name","PI Phone","PI Email","Business Contact Name","BC Phone","BC Email","Abstract" "SBIR Phase I: Enhancing the skin microbiome for mosquito repellency: Next generation mosquito repellent derived from big data analysis","$225,000.00"

This is the code that I found online that I've been trying to modify with zero success:
use strict; use Spreadsheet::WriteExcel; use Text::CSV_XS; # Check for valid number of arguments if ( ( $#ARGV < 1 ) || ( $#ARGV > 2 ) ) { die("Usage: csv2xls csvfile.txt newfile.xls\n"); } # Open the Comma Separated Variable file open( CSVFILE, $ARGV[0] ) or die "$ARGV[0]: $!"; # Create a new Excel workbook my $workbook = Spreadsheet::WriteExcel->new( $ARGV[1] ); my $worksheet = $workbook->add_worksheet(); # Create a new CSV parsing object my $csv = Text::CSV_XS->new; # Row and column are zero indexed my $row = 0; while (<CSVFILE>) { if ( $csv->parse($_) ) { my @Fld = $csv->fields; my $col = 0; foreach my $token (@Fld) { $worksheet->write( $row, $col, $token ); $col++; } $row++; } else { my $err = $csv->error_input; print "Text::CSV_XS parse() failed on argument: ", $err, "\n"; } }
I thought about converting to tab delimited or pipe delimited then converting to excel but it got to be possible so I'm reaching out to the monks who are always smarter and wiser than me. Thanks!

In reply to convert csv with quotes to xls by Anonymous Monk

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.