=head1 NAME B - Convert battleship CSV files to Excel =head1 SYNOPSIS conv2xls file ... =head1 DESCRIPTION Input is a CSV battleship puzzle file (or several files). Three files fit onto one printed page. Output is an Excel file F. Example: conv2xls p1 p2 p3 =cut use warnings FATAL => 'all'; use strict; use Excel::Writer::XLSX qw(); use File::Slurp qw(slurp); my $workbook = Excel::Writer::XLSX->new('puz.xlsx'); my $worksheet = $workbook->add_worksheet(); $worksheet->set_column(0, 10, 3); my $row = 0; for my $file (@ARGV) { my @lines; for (slurp($file)) { chomp; push @lines, [split /,/]; } push @lines, [' ']; my $row_rel = 0; for my $line (@lines) { my @cols = @{ $line }; my $col = 0; for my $data (@cols) { my $format = $workbook->add_format(); unless ($row_rel == 0 and $col == $#cols) { $format->set_align('center'); } if ($row_rel > 0 and $row_rel < $#lines-1 and $col < $#cols) { $format->set_border(1); $format->set_bold(); } $worksheet->write($row, $col, $data, $format); $col++; } $row++; $row_rel++; } }