#!/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();
In reply to Re^2: duplicating the rows and joining three lines into one using perl script
by rpinnam
in thread duplicating the rows and joining three lines into one using perl script
by rpinnam
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |