【问题标题】:Memory error while creating jasper report with xls format使用 xls 格式创建 jasper 报告时出现内存错误
【发布时间】:2014-05-14 06:31:04
【问题描述】:

我正在使用 jasper 报告创建报告。当我创建具有 12000 条记录的报告(pdf,xls)时,它工作正常,但是当我创建具有 40000 条记录的报告时,堆内存问题。问题仅在于 xls 格式。 pdf格式工作正常。我的代码如下。

Map hm = new HashMap();
JasperPrint print = null;
JRSwapFileVirtualizer virtualizer = null;
    JRSwapFile swapFile = new JRSwapFile("D://", 2048, 1024);
virtualizer = new JRSwapFileVirtualizer(2,swapFile,true);
JRVirtualizationHelper.setThreadVirtualizer(virtualizer);
hm.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(
                    list);
JRExporter exporter = null;
            if (type.toUpperCase().equalsIgnoreCase(FileTypes.PDF.name())) {
                exporter = new JRPdfExporter();

            } else if (type.toUpperCase().equalsIgnoreCase(FileTypes.XLS.name())) {
                exporter = new JRXlsExporter();
            }

            if(exporter != null)
            {
                exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
                        outFileName);
                exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
                exporter.exportReport();
            }

【问题讨论】:

    标签: java jasper-reports


    【解决方案1】:

    我找到了这个问题的解决方案。我已将 IS_IGNORE_PAGINATION 添加到 xls 文件中,所以它工作正常。

    Map hm = new HashMap();
    JasperPrint print = null;
    JRSwapFileVirtualizer virtualizer = null;
    JRSwapFile swapFile = new JRSwapFile("D://", 2048, 1024);
    virtualizer = new JRSwapFileVirtualizer(2,swapFile,true);
    JRVirtualizationHelper.setThreadVirtualizer(virtualizer);
    hm.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
    if (type.toUpperCase().equalsIgnoreCase(FileTypes.XLS.name()))
    {
        hm.put(JRParameter.IS_IGNORE_PAGINATION, new Boolean(false));
    }
    JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(
                        list);
    JRExporter exporter = null;
                if (type.toUpperCase().equalsIgnoreCase(FileTypes.PDF.name())) {
                    exporter = new JRPdfExporter();
    
                } else if (type.toUpperCase().equalsIgnoreCase(FileTypes.XLS.name())) {
                    exporter = new JRXlsExporter();
                }
    
                if(exporter != null)
                {
                    exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
                            outFileName);
                    exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
                    exporter.exportReport();
                }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-10
      • 1970-01-01
      • 2018-07-07
      • 1970-01-01
      • 2012-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多