http://qs321.pair.com?node_id=1009202

gw1500se has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that is working fine but I need to add one more touch. Given a certain cell content, I need to make the background color of that cell yellow. I have spent hours trying to use various things none of which work. This is what I am trying now.
my $format=$sheet->get_cell($i,$j)->get_format(); $format->set_color('yellow');
All I get is a null pointer error on the 2nd line. Can someone help? TIA.

Replies are listed 'Best First'.
Re: Set Background Color Using Spreadsheet::SaveParser
by jmcnamara (Monsignor) on Dec 17, 2012 at 17:13 UTC

    The get_format() in the first line returns a Spreadsheet::ParseExcel Format object which doesn't have a set_color() method, or set_anything() method since it is a read/information only object.

    Possibly you are getting it confused with a Spreadsheet::WriteExcel format method that you have in the same program. If that is the case, then you will have to map the Spreadsheet::ParseExcel format properties to Spreadsheet::WriteExcel format properties, one by one.

    --
    John.

      Thanks for the reply. Not exactly confused as much as not understanding the capabilities of each. I thought SaveParser was a combined ParseExcel and WriteExcel, rather than something completely different. Logically, it seems that if I can add rows with SaveParser then I should also be able to set attributes on those rows. In any case, how do I go about updating an existing spreadsheet if not with SaveParser? Do I need to instead use both ParseExcel and WriteExcel instead? Can WriteExcel update and existing spreadsheet?