Big jasper report in Excel causes corrupted file

I use jasperreports 3.5.3 to create a large (but simple) report. Only a table with rows.

When I list a large enough selection, the generated file is damaged. Excel warns the user, and some data is corrupted. But if I filter the data to show some lines, including offensive ones, that it generated normally.

Anyone have experience with this damaged excel file?

Tip: this happens on a Linux / Apache + JBoss server, but the same code on local Windows / Jboss works fine. I do not think that Apache in the middle has something to do. It must be something in the generation itself.

+3
source share
1 answer

It seems that jasperreports 3.5.3 can use two kinds of "use case authors". By default, it is an exporter JRXlsExporterand does not work very well with large files (at least in my Spring MVC project).

The workaround is using another exporter based on JExcelAPI. I could export data without problems with this.

To create jasperreport use JExcelAPI in the Spring MVC installation , you need to write a personalized class. It is very simple:

import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.export.JExcelApiExporter;

import org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsSingleFormatView;

// this is the view class you'll use, instead of JasperReportsXlsView
public class JasperReportsJExcelApiView extends AbstractJasperReportsSingleFormatView
{
    // copied from JasperReportsXlsView
    public JasperReportsJExcelApiView()
    {
        setContentType("application/vnd.ms-excel");
    }

    protected JRExporter createExporter()
    {
        // we create the JExcelAPIExporter, not the JRXlsExporter
        return new JExcelApiExporter();
    }

    // copied from JasperReportsXlsView (I think it says: write binary data, not text)
    protected boolean useWriter()
    {
        return false;
    }
}

You will need jxl.jar in your classpath from the JExcelAPI 2.6 distribution.

+2
source

Source: https://habr.com/ru/post/1733225/


All Articles