I want to fill the background of excel cells with colours made up from the known red, green and blue components of the colours. To do this I found I needed to use:
$sheet->Range($rng)->Interior -> {PatternColor} = rgb colour value
$sheet->Range($rng)->Interior -> {Pattern} = pattern value
This site https://docs.microsoft.com/en-us/office/vba/api/Excel.XlPattern gives ‘values’ for 20 patterns including xlPatternSolid which I thought would give me the whole cell filled with that colour. This was not the case as the Perl below shows.
This code gives an Excel spreadsheet where:
Column C is the key to a hash which holds the pattern ‘names’ such as xlPatternSolid
Column D gives the cell filled with the colour and effect of the pattern
Column E gives the value of the pattern ‘names’ as shown on the web-site.
Cell D20 is where the xlPatternSolid has been used. This has no colour instead of the solid colour I was hoping for. Also cell D3 has no colour – the name of this colour pattern xlPatternAutomatic – I was not sure what to expect for this.
I did notice that the sides of cells D20 and D3 are no longer there.
How can I get cells filled with the solid colour?
use strict "vars"; use OLE; use Win32::OLE::Const "Microsoft Excel"; sub RGB ($$$$) { my ($jr, $jg, $jb, $ret_c) =@_; $$ret_c = $jr + $jg * 256 + $jb *256** 2; } my ($excel, $workbook, $sheet, $rng, $jh); my ($jr, $jg, $jb, $patterncolour, $jq, $jqa); my %cell_interior_pattern; # list from https://docs.microsoft.com/en-us/office/vba/api/Excel.XlPa +ttern $cell_interior_pattern{1} = xlPatternAutomatic; $cell_interior_pattern{2} = xlPatternChecker; $cell_interior_pattern{3} = xlPatternCrissCross; $cell_interior_pattern{4} = xlPatternDown; $cell_interior_pattern{5} = xlPatternGray16; $cell_interior_pattern{6} = xlPatternGray25; $cell_interior_pattern{7} = xlPatternGray50; $cell_interior_pattern{8} = xlPatternGray75; $cell_interior_pattern{9} = xlPatternGray8; $cell_interior_pattern{10}= xlPatternGrid; $cell_interior_pattern{11}= xlPatternHorizontal; $cell_interior_pattern{12}= xlPatternLightDown; $cell_interior_pattern{13}= xlPatternLightHorizontal; $cell_interior_pattern{14}= xlPatternLightUp; $cell_interior_pattern{15}= xlPatternLightVertical; $cell_interior_pattern{16}= xlPatternNone; $cell_interior_pattern{17}= xlPatternSemiGray75; $cell_interior_pattern{18}= xlPatternSolid; $cell_interior_pattern{19}= xlPatternUp; $cell_interior_pattern{20}= xlPatternVertical; $excel = CreateObject OLE "Excel.Application"; $excel -> {Visible} = 1; $workbook = $excel -> Workbooks -> Add; $sheet = $workbook -> Worksheets("Sheet1"); $sheet -> Activate; $sheet -> Range('C2') -> {Value} = 'Index'; $sheet -> Range('D2') -> {Value} = 'Colour'; $sheet -> Range('E2') -> {Value} = 'Value of array index'; $jr = 120; $jg = 140; $jb = 55; RGB($jr, $jg, $jb, \$patterncolour); for $jq (sort {$a <=> $b} keys %cell_interior_pattern) { $jqa = $jq + 2; $rng = 'D' . $jqa; $sheet->Range($rng)->Interior -> {PatternColor} = $patternco +lour; $sheet->Range($rng)->Interior -> {Pattern} = $cell_interior_ +pattern{$jq}; $rng = 'E' . $jqa; $sheet -> Range($rng) -> {Value} = $cell_interior_pattern{$jq}; $rng = 'c' . $jqa; $sheet -> Range($rng) -> {Value} = $jq; }

In reply to Problem filling Excel cells with Solid Colour by merrymonk

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.