java - Access to the color palette in an XSSFWorkbook -


when using poi, cells , fonts in excel documents contain color information not return rgb value , offers index value. indexed value must looked against color. in hssfworkbook (xls) there method available palette:

inputstream in = new fileinputstream("sheet.xls"); hssfworkbook wb = new hssfworkbook(in); wb.getcustompalette(); 

when accessing xssfworkbook (xlsx) there no such method , in fact can find no palette information anywhere in related classes. able index value xssfont , cell, way color "name" match against indexedcolors enum. returns me same original problem; still have no rgb value use.

inputstream in = new fileinputstream("sheet.xlsx"); xssfworkbook wb = new xssfworkbook (in); wb.getcustompalette(); <-- fail! 

i getting xssfcolor way of cellstyle, so:

cellstyle style = cell.getcellstyle(); xssfcolor color = style.getfillbackgroundcolorcolor(); 

to color name via indexedcolors:

for (indexedcolors c : indexedcolors.values()) { if (c.index == indexcolor){ system.out.println("color: " + c.name()); } } 

similar questions: how (java apache poi hssf) background color given cell?

reference: http://poi.apache.org/spreadsheet/quick-guide.html#customcolors

update 1: i've found works, finally. method of xssfcolor returns argb hex code , can determine rgb values (obviously). hope helps save x number of hours same issue.

((xssfcolor) color).getargbhex()) 

update 2: dismay, i've found cells don't return background xssfcolor containing argbhex data. looking work-around this.

using wb.getstylessource(), can stylestable, can cellstyle objects. xssfcellstyle api has number of methods color objects - namely, xssfcolor. xssfcellstyle api has access fonts within style - namely, xssffont, can again xssfcolor object specific font.

once you've gotten access xssfcolor, call getrgb() return byte array of rgb values.


Comments

Popular posts from this blog

Need help in packaging app using TideSDK on Windows -

java - Why does my date parsing return a weird date? -

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -