CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Adding alternate row coloring in Excel

 



terrykhatri531
User

Aug 6, 2014, 11:52 AM

Post #1 of 2 (202 views)
Adding alternate row coloring in Excel Can't Post

Hi,

I am trying to add alternate colors to the rows in excel, I have tried using the following code but its not working for me :




Code
  
my @colors=( 'gray', 'silver' );
my $row=1;
while ($a = $sth->fetchrow_hashref()) {

my $url = qq(internal:$a->{OrderID}!A1);
my $string = qq('$a->{OrderID}');

$worksheet->write($row,0,$url,$string,$link_format);
$worksheet->write($row,1, $a->{CustomerName});
$worksheet->write($row,2, $a->{ShipName});
$worksheet->write($row,3, $a->{OrderDate});
$worksheet->write($row,4, $a->{ShipVia});
$worksheet->write($row,5, $a->{ShippedDate});
$worksheet->write($row,6, $a->{ShipAddress});
$worksheet->write($row,7, $a->{ShipCity});
$worksheet->write($row,8, $a->{ShipRegion});
$worksheet->write($row,9, $a->{ShipPostalCode});
$worksheet->write($row,10, $a->{ShipCountry});
$worksheet->write($row,11, $a->{Freight},$number);
$freight = $a->{Freight};
$ordid = $a->{OrderID};
$ordttl = $a->{'Total'} + $a->{'Freight'};
#$ordttl = sprintf("%.2f", $ordttl);
$worksheet->write($row,12,$ordttl,$number);
my $rowcolor = $colors[ $row++ % 2 ];

}


Thanks much for your help!!

Terry


(This post was edited by terrykhatri531 on Aug 6, 2014, 11:53 AM)


Zhris
Enthusiast

Aug 6, 2014, 12:01 PM

Post #2 of 2 (199 views)
Re: [terrykhatri531] Adding alternate row coloring in Excel [In reply to] Can't Post

Hi,

You haven't made use of $rowcolor / added a format for each write.

Here is a slightly modified snippet of the representative code, which works fine:

Code
my @colors=( 'gray', 'silver', 'red' );  
my $row = 0;
while ( $row < 10 )
{
my $rowcolor = $colors[ $row++ % @colors ];
print "$rowcolor\n";
}


Chris


(This post was edited by Zhris on Aug 6, 2014, 12:04 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives