Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.9.4

Bug #623 setBgColor sets color to black no matter what
Submitted: 2004-01-25 18:37 UTC
From: clay at skilltreeconsulting dot com Assigned: xnoguer
Status: Closed Package: Spreadsheet_Excel_Writer
PHP Version: 4.3.3 OS: Mac OS X, FreeBSD 4.8
Roadmaps: (Not assigned)    
Subscription  


 [2004-01-25 18:37 UTC] clay at skilltreeconsulting dot com
Description: ------------ When calling setBgColor on a cell, the color that appears in Excel v.X for Mac OS X is black. I have used 'grey', 14, and even setCustom Color to override index 14 to RGB values 192,192,192. Reproduce code: --------------- $workbook = new Spreadsheet_Excel_Writer(); $spread_name = "invoice.xls"; $workbook->send("$spread_name"); $worksheet =& $workbook->addWorksheet('Invoice'); $workbook->setCustomColor(14, 192,192,192); $grey_align_left =& $workbook->addFormat(); $grey_align_left->setBgColor(14); $worksheet->write(27, 5, "PAST DUE BALANCE", $grey_align_left); $workbook->close(); Expected result: ---------------- A cell with a grey background and black fonts. Actual result: -------------- a cell with a black background and black fonts.

Comments

 [2004-01-27 21:50 UTC] xnoguer at php dot net
could you try setFgColor(14)? The documentation is not clear about this actually, but the effects of setFgColor() and setBgColor() depend in the pattern being used (you can change it using setPattern()).
 [2004-02-18 06:05 UTC] pear-bugs at carldunham dot com
Yikes, this has been driving me batty also. I guess the "foreground" and "background" refer to the pattern, not the element having the format applied to it.
 [2004-11-02 18:55 UTC] rs234 at cornell dot edu
I am having the same problem with it on winxp office 2003. setting pattern afterwards doesn't seem to work either. has it been fixed yet?? It seems to be a rendering order of somesort between the background color and the pattern... as the pattern seems to have overwritten the color setting
 [2005-09-27 09:40 UTC] vonderheide at redlink dot de
Same problem here using Excel 2003: The background color is actually set using Format::setFgColor(), which should set the foreground color instead. Format::setBgColor() sets the background color to black instead of the specified color
 [2005-09-27 09:59 UTC] vonderheide at redlink dot de
Figured it out, please disregard my previous comment. The class Format provides 3 methods for setting colors: Format::setColor() is used to set the text color of a cell Format::setFgColor() and Format::setBgColor() set the two colors used by the pattern. So in order to set the background color, choose pattern 1 (solid fill) and use setFgColor(). Format::setBgColor() is only used for pattern that use two colors. Perhaps the documentation could be updated to emphasize this.
 [2006-05-17 19:13 UTC] danielc (Daniel Convissor)
Documentation was fixed a while ago.