Hi,
I'm trying to write the test code to set foreground colors to cells in a column
individually. But failed - the whole column is displaied in one color, actually the
last that was applyed to the cell style. What's wrong with my code?
How to write this code correctly?
Thanks,
Sergei.
short[] colors = {...}; // array of colors indexes like 'HSSFColor.AQUA.index'
etc.
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFCellStyle style = wb.createCellStyle();
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
HSSFFont font = wb.createFont();
HSSFRow row = null;
HSSFCell cell = null;
for (int i=0; i<colors.length; i++) {
row = sheet.createRow( (short) i);
cell = row.createCell( (short) 0);
style.setFillForegroundColor(colors[i]);
cell.setCellStyle(style);
cell.setCellValue(colors[i]);
}
FileOutputStream out = new FileOutputStream("excel_colors.xls");
wb.write(out);
out.close();