G'day CoVAX,

[Disclaimer: I'm not a regular user of Excel::Writer::XLSX — possibly last used a decade ago. Check any solutions by other monks; they may be much better.]

As your question revolved around colouring columns, I've just focussed on that aspect. I think the easiest thing would be to group the data by the required colours; that would avoid colouring individual cells. I believe the following does what you describe in terms of layout — I tested it by running this code as a standalone script and checking the pm_11166178.xlsx spreadsheet it created.

#!/usr/bin/env perl use v5.24; use warnings; use Excel::Writer::XLSX; my $workbook = Excel::Writer::XLSX::->new('pm_11166178.xlsx'); my $worksheet = $workbook->add_worksheet('C'); my @formats; { no warnings 'qw'; for my $colour (qw{#ED7D31 #4472C4 #00B050}) { push @formats, $workbook->add_format(bg_color => $colour); } } my @data = ( { token => [[qw{a b c}],[1,2,3]], row => 1, col => 0, format => $formats[0], }, { token => [[qw{d e f}],[4,5,6]], row => 1, col => 3, format => $formats[1], }, { token => [[qw{x y z}],[24,25,26]], row => 1, col => 6, format => $formats[2], }, ); for my $datum (@data) { $worksheet->write_col(@$datum{qw{row col token format}}); }

A hint for future reference: providing some ASCII art to describe the wanted layout can be better than a prosaic description (a picture paints a thousand words :-)

— Ken


In reply to Re: How to use Perl to assign different fill colors to columns in the same series of an Excel chart? by kcott
in thread How to use Perl to assign different fill colors to columns in the same series of an Excel chart? by CoVAX

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.