【问题标题】:Apache POI coded formatting works with MS excel 2010 but not in excel 2003Apache POI 编码格式适用于 MS excel 2010,但不适用于 excel 2003
【发布时间】:2012-08-10 14:38:44
【问题描述】:

我已经使用 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);

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

【问题讨论】:

  • 你没有使用style.setFont,你定义的字体怎么会在2010年显示正确?
  • @Alfabravo :我在原始代码中使用了 style.setFont(font)。因为我不能把所有的代码都放在这里,所以我修剪了一些代码。

标签: java apache-poi


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2012-08-10
    • 2021-10-27
    • 2018-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-12
    • 1970-01-01
    • 2021-10-09
    相关资源
    最近更新 更多