Notice how I set up a format, like $fmtdef, then use that in a write statement.
use Spreadsheet::WriteExcel;
my($xlsfnout,$row,$workbook,$sheet);
$xlsfnout = $basefn.".xls";
if (-e $xlsfnout) # First deleted old SS.
{
unlink $xlsfnout or die "ERROR: Could not delete $xlsfn";
}
$workbook = Spreadsheet::WriteExcel->new($xlsfnout);
if (!$workbook)
{
$s="ERROR: Could not create workbook for $xlsfnout";
writeerr($s);
exit 1;
}
# Add a worksheet and set print options.
$sheet = $workbook->add_worksheet('Sheet1');
$sheet->print_row_col_headers(); # Print cell letters and numbers
$sheet->print_across(); # For wide pages that don't fit on one page.
$sheet->set_footer('&CPage &P',0.25);
$sheet->set_header('&C&Z&F&R&D &T',0.25);
$sheet->set_landscape();
$sheet->set_print_scale(80); # Print zoom.
#$sheet->set_paper(3); # 0=printer default, 3 or 4=11x17
$sheet->freeze_panes(1,0); # Freeze top row only
$sheet->set_margins(0.5); # Inches
$sheet->set_margins_LR(0.5); # Inches
#$sheet->set_zoom(75); # '75' = 75%. View zoom.
# Change width for only first column
# Do set_column() or set_row() before any writes.
$sheet->set_column(0,0,20); # (col start, col end, width). Also set_column('A:B',20);
# Define the format and add it to the worksheet
# Define a custom color.
my $tan=$workbook->set_custom_color(40,0xDB,0xB8,0x4d); # (index, r, g, b)
my $fmttan = $workbook->add_format(
font => 'Arial',
size => 10,
color => 'black',
bg_color => $tan,
align => 'left'
);
# Default format.
my $fmtdef = $workbook->add_format(
font => 'Arial',
size => 10,
color => 'black',
align => 'left'
);
$format = $workbook->add_format(
center_across => 1,
bold => 1,
size => 10,
border => 4,
color => 'black',
bg_color => 'cyan',
border_color => 'black',
align => 'vcenter',
);
# Hdr
$t=`pwd`;
chomp($t);
@a=(@a,"Extracted from $filename using ".$t.'/'.$0);
$row=0;
for ($i=0; $i<=$#a; $i++) # Write hdr
{
$sheet->write($row,$i, $a$i, $fmtdef); # (row,col,data,fmt)
}
$row++;
# Write details
for ($i=0; $i<=$#a; $i++) # Write one detail line
{
$sheet->write($row,$i, $a$i, $fmtdef); # (row,col,data,fmt)
}
$row++;
$workbook->close();
In reply to Re: various Excel::Writer::SLSX questions
by bulrush
in thread various Excel::Writer::SLSX questions
by fionbarr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |