in reply to XLS to CSV file with Text wrap
Note that a text-wrap in Excel does not mean that the data in the cell will contain new-lines when you read it with Spreadsheet::ParseExcel. It is a display-feature in Excel. When you want the CSV to do something similar, you need to read the column-width and wrap the text yourself with something like Text::Wrap. Note however that the default font in Excel is most likely a variable width font and not a mono-spaced font like on a terminal, so that your wrapped text might wrap on completely different points in the field content.
corion's solution is already helpful (but it skips undefined fields), and could correctly deal with wrapped text, but if the sheet is huge, you might want to stream
my $csv = Text::CSV_XS->new ({ binary => 1, eol => "\r\n", auto_diag = +> 1 }); open my $fh, ">", "file.csv" or die "file.csv: $!"; foreach my $row_index ($source_sheet->row_range) { my @row; foreach my $col_index ($source_sheet->col_range) { my $source_cell = $source_sheet->{Cells}[$row_index][$col_inde +x]; my $value; if ($source_cell) { local $Text::Wrap::columns = 20; $value = wrap ("", "", $source_cell->Value); } push @row, $value; } $csv->print ($fh, \@row); } close $fh;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: XLS to CSV file with Text wrap
by kshitij (Sexton) on Sep 02, 2018 at 04:13 UTC | |
by Tux (Canon) on Sep 02, 2018 at 08:01 UTC | |
by kshitij (Sexton) on Sep 02, 2018 at 11:56 UTC | |
by poj (Abbot) on Sep 03, 2018 at 13:20 UTC | |
by kshitij (Sexton) on Sep 03, 2018 at 17:36 UTC | |
| |
by poj (Abbot) on Sep 02, 2018 at 06:38 UTC | |
by kshitij (Sexton) on Sep 03, 2018 at 06:54 UTC |