我试图执行以下测试(主要是从Apache POI homepage复制)来验证API是否正常工作。测试不会抛出异常,但是当我查看生成的Excel文件时,彩色单元格(0,0 = A1)实际上是纯白色的。没有应用颜色。单元格值已正确设置。使用Apache POI在XSSFCell中设置填充颜色不起作用
我正在使用POI 3.9-20121203 (stable)
。
缺少什么我在这里?为什么这个例子不能按预期工作?
@Test
public void test() throws FileNotFoundException, IOException
{
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet();
XSSFRow row = sheet.createRow(0);
XSSFCell cell = row.createCell(0);
cell.setCellValue("custom XSSF colors");
XSSFCellStyle style1 = wb.createCellStyle();
style1.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128)));
style1.setFillPattern(CellStyle.SOLID_FOREGROUND);
File f = new File("test.xlsx");
f.delete();
FileOutputStream fos = new FileOutputStream(f);
wb.write(fos);
fos.close();
}