in reply to Re^3: XLS to CSV file with Text wrap
in thread XLS to CSV file with Text wrap
I think you are right I am looking for a pre formatted xls into CSV and I think CSV is not used for that. I am changing my strategy. Now I am thinking to split the original XLS into multiple small XLS based on the pattern match and then format these XLS files based on other pattern match.
To achieve this , I am trying below code. My intention is to split the big XLS file into small xls file based on the pattern match of the range of lines but while writing out the smaller xls based on above pattern match , I am getting empty xls.
I am trying to match range of lines between /DFT Tasks for Ration/ and /END OF RATION/ and write it into separate xls.
Please provide your valuable inputs#!/usr/bin/perl -w use strict; use Spreadsheet::ParseExcel; use Spreadsheet::WriteExcel; my $parser = Spreadsheet::ParseExcel->new(); my $workbook = $parser->parse('Project_status_tracking_DFT.xls'); if ( !defined $workbook ) { die $parser->error(), ".\n"; } my $workbook1 = Spreadsheet::WriteExcel->new('Ration_Status.xls'); my @color = qw(white green orange pink blue magenta silver); my @format; for my $i (1..@color){ $format[$i] = $workbook1->add_format(bg_color => $color[$i]); $format[$i]->set_text_wrap(); } for my $worksheet ( $workbook->worksheets() ) { my $worksheet1 = $workbook1->add_worksheet(); my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); # set minimum column width my @width; $width[$_] = 10 for ($col_min .. $col_max); for my $row ( $row_min .. $row_max ) { my @value = (); my $fmt; # format for complete row # store row in array for my $col ( $col_min .. $col_max ) { my $cell = $worksheet->get_cell( $row, $col ); if (defined $cell) { if ( $cell =~ /DFT Tasks for Ration/ .. /END OF RATION/) { $value[$col] = $cell->value() ; if ($value[$col] =~ m/Completed/i){ $fmt = $format[1] } # determine max width for each column my $len = length($value[$col]); $width[$col] = $len if $len > $width[$col]; } } } # write row for my $col ( $col_min .. $col_max ) { $worksheet1->write($row, $col, $value[$col],$fmt); } } # set column widths for my $col ( $col_min .. $col_max ) { $worksheet1->set_column($col,$col,$width[$col]) } }
Thanks Kshitij
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: XLS to CSV file with Text wrap
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 | |
by kshitij (Sexton) on Sep 04, 2018 at 11:03 UTC | |
by poj (Abbot) on Sep 04, 2018 at 11:24 UTC | |
|