in reply to Re: duplicating the rows and joining three lines into one using perl script
in thread duplicating the rows and joining three lines into one using perl script
#!/usr/bin/perl -w use strict; use Spreadsheet::WriteExcel; my $workbook = new Spreadsheet::WriteExcel("test.xls"); my $sheet = $workbook->add_worksheet(); my $moneyFormat = $workbook->add_format(); $moneyFormat->set_num_format('$#,##0'); my $boldFormat = $workbook->add_format(); $boldFormat->set_bold(); my $row=0; my @longest=(0,0,0,0,0,0,0); open(MOV, "<test.csv") || die "Can't open movies.csv: $!"; while(<MOV>) { chomp; my @fields = split(/,/, $_); for(my $col = 0; $col < @fields; $col++) { if ($row == 0) { $sheet->write($row, $col, $fields[$col], $boldFo +rmat); } else { if ($col == 2 or $col == 3) { $sheet->write($row, $col, $fields[$col], $moneyForma +t); } else { $sheet->write($row, $col, $fields[$col]) +; } } if ($longest[$col] < length($fields[$col])) { $longest[$col] = length($fields[$col]); } } $row++; } $longest[2]+=3; $longest[3]+=3; for(my $i = 0; $i < @longest; $i++) { $sheet->set_column($i,$i,$longest[$i]); } close(MOV); $workbook->close();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: duplicating the rows and joining three lines into one using perl script
by graff (Chancellor) on Oct 07, 2015 at 02:46 UTC | |
by Laurent_R (Canon) on Oct 07, 2015 at 08:06 UTC | |
by graff (Chancellor) on Oct 08, 2015 at 00:43 UTC | |
by Laurent_R (Canon) on Oct 08, 2015 at 07:40 UTC | |
|
Re^3: duplicating the rows and joining three lines into one using perl script
by Anonymous Monk on Oct 07, 2015 at 02:45 UTC |