g0n has asked for the wisdom of the Perl Monks concerning the following question:
I'm programatically generating a word document which contains tables. I need to set the top row cells of certain tables to have a background colour of 'gray30'. By recording and examining macros I got as far as BackgroundPatternColor, but it only seems to do anything when I supply a number:
$table->Cell(1,1)->Range->{Shading}->{BackgroundPatternColor} = 254;
Supersearching and googling hasn't got me any further towards what the number codes are, so I decided to find out empirically:
use strict; use warnings; #create a word doc with all the background colour codes use Win32::OLE; my $word = CreateObject Win32::OLE 'Word.Application' or die $!; $word->{'Visible'} = 1; my $document = $word->Documents->Add; my $colour=0; my $selection = $word->Selection; my $table = $document->Tables->Add($selection->Range,2000,1); for (0..2000) { $table->Cell($colour,1)->Range->{Text} = "Colour $colour"; $table->Cell($colour,1)->Range->{Shading}->{BackgroundPatternColor +} = $colour; $selection->TypeParagraph; $selection->TypeParagraph; $selection->MoveDown({count=>1}); $colour++; }
This little script produces a word doc, with a very large table in it, each cell of which is a different colour. When I run it, I get a range of colour from 'red so dark as to be black' up to carmine at 255, then it starts at 'red so dark as to be black' again.
Can someone point me in the right direction?
TIA
--------------------------------------------------------------
"If there is such a phenomenon as absolute evil, it consists in treating another human being as a thing."
John Brunner, "The Shockwave Rider".
Can you spare 2 minutes to help with my research? If so, please click here
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Win32::OLE, Word, and BackgroundPatternColor
by jdporter (Paladin) on Mar 29, 2006 at 16:17 UTC |