Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
"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: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!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"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: convert csv with quotes to xls
by Tux (Canon) on Nov 22, 2019 at 07:28 UTC | |
|
Re: convert csv with quotes to xls
by marto (Cardinal) on Nov 21, 2019 at 21:26 UTC | |
|
Re: convert csv with quotes to xls
by trwww (Priest) on Nov 22, 2019 at 03:35 UTC |