开发者

Large jasper report to Excel causes a corrupt file

I'm using jasperreports 3.5.3 for generating a large (but simple) report. Only a table with strings.

When I list a big enough selection the generated file is corrupt. Excel alerts the user and some data is corrupted. But if I filter the data to show some rows including the offending one it's generated normally.

Does someone have experience with this corrupt excel file results?

Tip: it happens in a Linux/Apache+JBoss server, but the same code on a local Windows/Jboss works fine. I don't think the Apache in the middle has something to do. It must be something in the generatio开发者_如何学编程n itself.


It seems that jasperreports 3.5.3 can use two kinds of "excel writers". The by default exporter is JRXlsExporter and doesn't work very well with big files (at least in my Spring MVC project).

A workaround is using the other exporter, based in JExcelAPI. I could export the data without trouble with this one.

For making jasperreport use JExcelAPI into a Spring MVC instalation you have to write a personalized class. Its 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'll need the jxl.jar in your classpath from the JExcelAPI 2.6 distribution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜