【问题标题】:Excel Apache POI Printing IssueExcel Apache POI 打印问题
【发布时间】:2013-11-20 11:08:31
【问题描述】:

我正在使用 Apache POI 生成动态 Excel。

我有彩色单元格。对于我使用的颜色

headerCellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); headerCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

Excel 以完美的颜色生成,但当我打印时,此 Excel 的背景颜色带有点阴影。

我尝试并检查了以下内容:

  1. 不是打印机问题
  2. 当我将生成的 excel 的内容复制到新的 excel 中时。它的印刷非常完美。

所以代码或 POI 肯定有问题。

【问题讨论】:

  • 你有什么样的打印机?激光单色? ;-)
  • 如果生成了正确颜色的excel。那么代码是正确的。检查打印机设置

标签: java excel printing apache-poi


【解决方案1】:

如果 excel 生成正确,那么我认为这不是 Apache poi/code 的问题。

我正在粘贴Apache poi官方页面的示例。

如果有问题,请检查并验证您的代码:::

 Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("new sheet");

// Create a row and put some cells in it. Rows are 0 based.
Row row = sheet.createRow((short) 1);

// Aqua background
CellStyle style = wb.createCellStyle();
style.setFillBackgroundColor(IndexedColors.AQUA.getIndex());
style.setFillPattern(CellStyle.BIG_SPOTS);
Cell cell = row.createCell((short) 1);
cell.setCellValue("X");
cell.setCellStyle(style);

// Orange "foreground", foreground being the fill foreground not the font color.
style = wb.createCellStyle();
style.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
cell = row.createCell((short) 2);
cell.setCellValue("X");
cell.setCellStyle(style);

// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();

【讨论】:

    猜你喜欢
    • 2015-03-19
    • 2013-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    • 2012-03-04
    相关资源
    最近更新 更多