This is in reference to one requirement in which I need to convert one XLS file into CSV file with the help of Perl script. I have written below stated script . It is doing the job but the problem is the generated CSV file is having mismanaged data since the script is not taking care of Text wrap which was there in the XLS and the long strings of some cells are affecting other cells and CSV file is not getting generated as per my expectation.
#!/usr/bin/perl use Text::CSV_XS; use strict; use Spreadsheet::ParseExcel; my $sourcename = shift @ARGV or die "invocation: $0 <source file>\n"; my $source_excel = new Spreadsheet::ParseExcel; my $source_book = $source_excel->Parse($sourcename) or die "Could not +open source Excel file $sourcename: $!"; my $storage_book; foreach my $source_sheet_number (0 .. $source_book->{SheetCount}-1) { my $source_sheet = $source_book->{Worksheet}[$source_sheet_number]; print "--------- SHEET:", $source_sheet->{Name}, "\n"; next unless defined $source_sheet->{MaxRow}; next unless $source_sheet->{MinRow} <= $source_sheet->{MaxRow}; next unless defined $source_sheet->{MaxCol}; next unless $source_sheet->{MinCol} <= $source_sheet->{MaxCol}; foreach my $row_index ($source_sheet->{MinRow} .. $source_sheet->{Max +Row}) { foreach my $col_index ($source_sheet->{MinCol} .. $source_sheet->{Ma +xCol}) { my $source_cell = $source_sheet->{Cells}[$row_index][$col_index]; if ($source_cell) { #print "( $row_index , $col_index ) =>", $source_cell->Value, ","; print $source_cell->Value, ","; } } print "\n"; } print "done!\n";
In reply to XLS to CSV file with Text wrap by kshitij
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |