in reply to Re: XLS to CSV file with Text wrap
in thread XLS to CSV file with Text wrap
Thanks for providing the solution. I have tried it out but the generated CSV file is not getting generated properly. It is splitting most of the content in the newlines in the CSV file and coming in a single column .
Please find my script .#!/usr/bin/perl -w #use Text::CSV_XS; use strict; use warnings; use lib '/home/users/kulshrk/perl_module/lib64/perl5'; use Spreadsheet::ParseExcel; use Text::Wrap; use Text::CSV_XS; #use Text::CSV_XS qw( csv ); my $csv = Text::CSV_XS->new ({ binary => 1, eol => "\r\n", auto_diag = +> 1 }); open my $fh, ">", "Project_status_tracking_DFT.csv" or die "Project_st +atus_tracking_DFT.csv: $!"; 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; #my $sheet = []; 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}; # my $sheet = []; foreach my $row_index ($source_sheet->{MinRow} .. $source_sheet->{Max +Row}) { my @row; foreach my $col_index ($source_sheet->{MinCol} .. $source_sheet->{Ma +xCol}) { my $source_cell = $source_sheet->{Cells}[$row_index][$col_index]; my $value; if ($source_cell) { local $Text::Wrap::columns = 20; $value = wrap ("", "", $source_cell->Value); } push @row , $value; } $csv->print ($fh, \@row); } } close $fh;
Could you suggest something here ? I played with local $Text::Wrap::columns by changing the width but still issue is there .
Thanks Kshitij
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: XLS to CSV file with Text wrap
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 03, 2018 at 19:19 UTC | |
| |
|
Re^3: XLS to CSV file with Text wrap
by poj (Abbot) on Sep 02, 2018 at 06:38 UTC | |
by kshitij (Sexton) on Sep 03, 2018 at 06:54 UTC |