I have an existing excel spreadsheet, which I am accesssing and reading values from, I am using Apache POI HSSF.
It is initialised like this:
HSSFSheet sheet;
FileInputStream fis = new FileInputStream(this.file);
POIFSFileSystem fs = new POIFSFileSystem(fis);
HSSFWorkbook wb = new HSSFWorkbook(fs);
this.sheet = wb.getSheet(exsheet);
I am iterating over all the cells that exist in the sheet, which makes a cell object:
HSSFCell cell = (HSSFCell) cells.next();
Please can someone familiar with the framework explain how to create an (HSSFColor) object to represent the backround color of each cell in the sheet.
Many thanks
EDIT, UPDATE
To be clear what I want to know is: how do I create/get an HSSFColor object for the background color of an existing cell?
cell.getCellStyle().getFillBackgroundColor();
This code only returns a short number, not an HSSFColor object. Thanks for the answers so far.
The backgroundcolor information of XSSFCellStyle can get from the method:
You can print it out and you will see it's structure.
For XSSF reading xlsx file (tried the HSSF as well) ,after struggle for a while, i just found
getFillBackgroundXSSFColor()
method actually returned the "Pattern Color" in the Fill tab of "Format Cells" in Excel, not the so-called "Background" color in that tab. I am not sure if this expected.See my below screenshot. The returned RGB is actually FF0000 ,i.e. RED.
So right now, I do not have a way for this case and just request user to fill the "Pattern Color" as well.