You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Dennis Allen <dw...@gmail.com> on 2007/08/04 05:17:46 UTC

Modifying specific cell colors/fonts

I'm using the sample application as a starter to read in an existing
spreadsheet , modify a few cells, and write the result to a new
spreadsheet.  If I only write values, everything works fine.  If I try to
modify the fonts/colors of a particular cell, other cells are affected.  The
code below attempts to modifty only one cell. but the resulting spreadsheet
ends up with a large number of cells changing.  The additional cells that
change are the same from one iteration to another, but if I change a
specific cell color within Excel, then only that one cell changes,so it
doesnt appear that Excel itself is propagating the change.


I read somewhere that changing certain cellstyle properties would affect
later cell writes, but that does not appear to vbe what is going on here.


Any help appreciated.


HSSFRow row = sheet.getRow(1);

HSSFCell cell = row.getCell(( *short* ) 1);

HSSFFont font = wb.getFontAt(( *short* )1);

HSSFCellStyle cellStyle = wb.createCellStyle();

cell.setCellType(HSSFCell.*CELL_TYPE_STRING*);

cell.setCellValue("MODIFIED CELL!!!!!");

font.setBoldweight(font.*BOLDWEIGHT_BOLD*);

cellStyle.setFillForegroundColor(HSSFColor.LIME.*index*);

cellStyle.setFillPattern(HSSFCellStyle.*SOLID_FOREGROUND*);

font.setColor(HSSFColor.RED.*index*);

cellStyle.setFont(font);

cell.setCellStyle(cellStyle);

 wb.write(stream);

stream.close();