This is my code for writing an XLS file, but the concepts should be very similar. One reason I didn't use the XLSX routines is the poor documentation.

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();

Perl 5.8.8 on Redhat Linux RHEL 5.5.56 (64-bit)

In reply to Re: various Excel::Writer::SLSX questions by bulrush
in thread various Excel::Writer::SLSX questions by fionbarr

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.