【问题标题】:JRXlsxExporter generating improper xls fileJRXlsxExporter 生成不正确的 xls 文件
【发布时间】:2016-10-11 15:40:06
【问题描述】:

我正在使用 jasper 模板来生成 pdf 和 xls 文件。以下是我生成 xls 文件的方法。

private void exportXls(List<JasperPrint> jasperPrintList, ByteArrayOutputStream baos) {
        JRXlsxExporter exporter = new JRXlsxExporter();
        exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList));
        exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(baos));

        SimpleXlsxReportConfiguration config = new SimpleXlsxReportConfiguration();
        config.setOnePagePerSheet(Boolean.FALSE);
        config.setDetectCellType(Boolean.TRUE);
        config.setIgnoreCellBackground(false);
        config.setWrapText(true);
        config.setRemoveEmptySpaceBetweenRows(true);
        config.setCollapseRowSpan(true);
        exporter.setConfiguration(config);

        try {
            exporter.exportReport();
        } catch (JRException e) {
            throw new RuntimeException(e);
        }
    }

PDF 生成工作正常,但 excel 生成错误如下,合并了几列

有没有办法生成excel,让每个条目占据一个单元格?

【问题讨论】:

  • 您应该修复报表设计。您是否为报告期间、报告日期和报告日期使用不同的文本字段?如果是,那么它实际上会导致您的 xls 导出出现问题。尝试将文本字段的开始和结束与表格列的开始和结束值相匹配。例如,假设您有文本字段“报告期间”,那么它的宽度和高度应与您的列“类型”匹配。同样,您需要匹配其他文本字段才能删除合并列。

标签: java jasper-reports export-to-excel


【解决方案1】:

Jasper Reports 提供所谓的像素完美导出。导出到 Excel 或 Word 时,它分别使用许多列或像素完美的表格来表示绘制的报告。

如果您想查看所有列,可以导出 csv 文件。当然,那些是没有格式的。

据我所知,没有其他设置可以改变这种行为。

【讨论】:

    猜你喜欢
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-03
    • 1970-01-01
    相关资源
    最近更新 更多