我想将单元格的颜色更改为用java.awt.Color [r = 255,g = 255,b = 255]定义的颜色,我使用了代码:
Color sColor = new Color(200, 0, 0);
XSSFColor userColor = new XSSFColor(sColor);
try
{
CellStyle style = wb.createCellStyle();
Font font = wb.createFont();
font.setColor(userColor.getIndexed());
style.setFont(font);
cell.setCellStyle(style);
}
catch (NumberFormatException | NullPointerException ex)
{
//Handle NumberFormat and NullPointer exceptions here
}
颜色始终保持黑色。
的输出System.out.print(userColor);是:>(org.apache.poi.xssf.usermodel.XSSFColor@2e1b928)。实际上,它会根据我输入的值而变化new Color (200,0,0);
但的输出System.out.print(userColor.getIndexed());始终为:(0)。
有小费吗?
相关分类