Social Icons

Pages

Saturday, July 4, 2015

Apache POI- Convert Excel column number to letter & Create color using RGB

Recently I had chance generating a complex excel file using Apache POI. I spent a few hours finding formulas.

In this article, I am going to share those formulas.  Hope this will helpful for you.

//Convert excel column number to letter
import org.apache.poi.hssf.util.CellReference
String letter = CellReference.convertNumToColString(ColumnNumber);


// Create color using RGB code
import org.apache.poi.hssf.usermodel.HSSFPalette;
HSSFPalette palette = workbook.getCustomPalette();
palette.setColorAtIndex(new Byte((byte) 10), new Byte((byte) 22), new Byte((byte) 54), new Byte((byte) 92));
//(short index,byte red,byte green, byte blue) - index - the palette index, between 0x8 to 0x40 inclusive
 
HSSFCellStyle worksheetCellStyle = workbook.createCellStyle();

worksheetCellStyle.setFillForegroundColor(palette.getColor(10).getIndex());

No comments:

Post a Comment