2

我已经使用 Apache POI 为 excel 编写了颜色格式代码。颜色和字体的格式在 MS Excel 2010 中很好。但它与 excel 2003 不兼容。在 MS Excel 2003 中打开文件时,格式不存在。

这里是示例代码:

    CellStyle style = getWorkbook().createCellStyle();

    Font font = wb.createFont();
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setFontHeightInPoints((short)11);

    style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);

    Cell cell = excelRow.createCell(10);
    cell.setCellStyle(style);

如果有任何建议,请告诉我。

4

1 回答 1

1

我也遇到过同样的问题。这与 excel 版本无关。我们必须在循环之前创建样式,并在创建后将样式应用于特定的单元格。

https://stackoverflow.com/a/11792648/1211000(可能有帮助)

于 2012-08-16T06:46:41.027 回答