I have an excel sheet where additions have a red background, changes have a yellow background, and deletions are grey. What I am hoping to do is read through the sheet, and based on the cell background color, perform the relevant database action.
Normally I would make each type of action in its own column, or add another column to determine action.
What options do I have for getting at the "format" that comes back in the spreadsheet object?
Thanks
Relying on cell color sounds brittle IMO. Assigning an explicit action column would be a better approach IMO.
That said, it is possible to access the color. However, there are no built in CF methods. You must dip into the underlying POI. First iterate through the cells in the spreadsheet:
Then for each cell, extract the style color. Not tested, but something like this should work. (See XSSFColor)
Update:
As @Sean mentioned in the comments, CF9 does not have the method above. Unfortunately
getFillForegroundColorColor()
andgetARGBHex()
were introduced sometime around 3.7, but CF is bundled with an earlier version: 3.5 (I think). So you must use the indexed color method instead (or upgrade the POI jars).