I am not sure why the text wrap is not happening

Probably because you are setting the column widths to the maximum length of the string. Also you are only applying a text wrap format to rows that match 'completed'. You need a default text wrap for the other rows. It looks like you want to create the new spreadsheet with the same column widths as the original. Try this

#!/usr/bin/perl use strict; use warnings; 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_ksh.xls'); my @color = qw(white green orange pink blue magenta silver); my @format; $format[0] = $workbook1->add_format(); $format[0]->set_text_wrap(); 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(); my $col_widths = $worksheet->get_col_widths(); my $flag = 0; for my $row ( $row_min .. $row_max ) { my $fmt = $format[0]; # default format for complete row # store row in array my @value = (); for my $col ( $col_min .. $col_max ) { # set column width same as source $worksheet1->set_column($col, $col, $col_widths->[$col]) if ($ro +w == $row_min); my $cell = $worksheet->get_cell( $row, $col ); if (defined $cell) { my $value = $cell->value(); $value[$col] = $value; if ($value =~ /DFT Tasks for Ration/){ $flag = 1; } elsif ($value =~ /END OF RATION/){ $flag = 2; }; if ($value =~ m/Completed/i){ $fmt = $format[1] } } } # write row if ($flag){ for my $col ( $col_min .. $col_max ) { $worksheet1->write($row, $col, $value[$col],$fmt); } $flag = 0 if $flag == 2; } } }
poj

In reply to Re^7: XLS to CSV file with Text wrap by poj
in thread XLS to CSV file with Text wrap by kshitij

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.