首页 文章

Excel Apache POI打印问题

提问于
浏览
0

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

我有彩色细胞 . 对于我正在使用的颜色

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

用完美的颜色生成的Excel但是当我打印这个excel背景颜色时带有点缀的阴影 .

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

  • 这不是打印机问题

  • 当我将生成的excel的内容复制到新的excel时 . 它的印刷品非常完美 .

所以在代码或POI中一定有问题 .

1 回答

  • 2

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

    我从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();
    

相关问题