Domanda

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. the problem is only with the xls format. pdf format works fine. 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();
            }
È stato utile?

Soluzione

I found the soluation of this question . i have added the IS_IGNORE_PAGINATION to the xls file so it works fine.

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();
            }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top