简体   繁体   English

使用xls格式创建jasper报告时出现内存错误

[英]Memory error while creating jasper report with xls format

i am creating report using jasper report. 我正在使用碧玉报告创建报告。 when i create report(pdf,xls) with 12000 records it's work fine but when i create report with 40000 records problem of heap memory. 当我创建具有12000条记录的报告(pdf,xls)时,它的工作正常,但是当我创建具有40000条记录的报告时,则出现了堆内存问题。 the problem is only with the xls format. 问题仅在于xls格式。 pdf format works fine. pdf格式工作正常。 my code is below. 我的代码如下。

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();
            }

I found the soluation of this question . 我找到了解决这个问题的办法。 i have added the IS_IGNORE_PAGINATION to the xls file so it works fine. 我已经将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();
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM