dhoerl / DHlibxls

Framework to read Excel xls spreadsheets
271 stars 86 forks source link

Can I get Background color of each row(cell) from excel sheet ? #22

Closed ManiMurugan123 closed 9 years ago

ManiMurugan123 commented 9 years ago

I need to get the color while importing(reading) excel file into my project. Is it Possible ?

dhoerl commented 9 years ago

Yes, its possible. You will have use the C interface into libxls.

1)The libxls cell st_xls_cell is first read here, in DHxlsReader.c: xlsCell *cell = &rowP->cells.cell[tt]

2) Assuming this is a BIFF8 file (which it almost certainly is, but you can test for it), then that xlsCell has a field called "xf" - the index of the the format record of type st_xf (extended format record).

3) You need to read in the worksheet record, and get the pointer to the list of format records (see st_xf xfs; //XF table). The "xf" number in the cell is an index into this table. Read the st_xf record.

4) The format has a color in it of "groundcolor;" That word has bitfields in it, including all sorts of colors. See https://www.openoffice.org/sc/excelfileformat.pdf page 224 (BIFF8). I assume the color you see iis the "pattern colour"

Now, this looks good - but wait, its more complicated. If the color is set by a whole row, then the format will come from the row record, or column record. As long as the color has been applied per cell, you will get it. Excel is a complicated format.

ManiMurugan123 commented 9 years ago

Thanks a lot dhoerl. It works like a charm. thanks again.