所以我試圖色細胞使用該功能基於某些特定的值:除着色部分其他細胞
public static void styleExceptions(CellStyle Exstyle, Font Exfont, Cell cell, AdditiveInformation obj){
Exfont.setFontHeightInPoints((short) 10);
Exfont.setFontName("Calibri");
Exstyle.setFont(Exfont);
Exstyle.setAlignment(CellStyle.ALIGN_CENTER);
Exstyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
Exstyle.setBorderBottom(CellStyle.BORDER_DOUBLE);
Exstyle.setBorderRight(CellStyle.BORDER_THIN);
Exstyle.setBorderLeft(CellStyle.BORDER_THIN);
Object result=null;
cellToType(cell,result);
if(result instanceof Double){
if((Double)result==obj.get_xmonthreq() || (Double)result==obj.get_xmonthbalance() ||
(Double)result==obj.get_xmonthendstock()){
Exstyle.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex());
Exstyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
}
else if((Double)result==obj.get_ymonthreq() || (Double)result==obj.get_ymonthbalance() ||
(Double)result==obj.get_ymonthendstock()){
Exstyle.setFillForegroundColor(IndexedColors.LIGHT_ORANGE.getIndex());
Exstyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
Exstyle.setBorderBottom(CellStyle.BORDER_DOUBLE);
}
else if((Double)result==obj.get_zmonthreq() || (Double)result==obj.get_zmonthbalance() ||
(Double)result==obj.get_zmonthendstock()){
Exstyle.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
Exstyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
Exstyle.setBorderBottom(CellStyle.BORDER_DOUBLE);
}
}
}
一切工作的功能,我我做的事情結果對象錯誤,導致沒有滿足條件的單元格被着色。
這個的cellToType方法:
private static void cellToType(Cell cell, Object result){
switch(cell.getCellType()){
case Cell.CELL_TYPE_NUMERIC:
if(DateUtil.isCellDateFormatted(cell)){
result= cell.getDateCellValue();
}
else
result=cell.getNumericCellValue();
break;
case Cell.CELL_TYPE_STRING:
result=cell.getStringCellValue();
break;
case Cell.CELL_TYPE_BOOLEAN:
result=cell.getBooleanCellValue();
break;
case Cell.CELL_TYPE_FORMULA:
result=cell.getCellFormula();
break;
default:
throw new RuntimeException("There is no support for this type of cell");
}
}
你沒有使用'cell.setCellStyle(擴展風格);'任何地方...... 設定的樣式後,您需要申請所需的細胞的cellstyle。 – Sankumarsingh