Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting Jasper Reports to XLSX format with Spring 3.0.5

I am using Spring MVC with 3.0.5 release and have reports which export reports to PDF and XLS. But recently I am facing an issue with XLS reporting since it does not support 65,000+ rows. Hence I now need to export to XLSX foramt.

Currently Spring provides Jasper views for XLS, PDF, HTML, CSV and something called as multiformatview

This is how we are configuring the view at present

<bean id="xlsReport"  class="org.springframework.web.servlet.view.jasperreports.JasperReportsXlsView">
    <property name="url"
        value="/WEB-INF/classes/jasper/FinanceReport.jrxml" />
    <property name="reportDataKey" value="datasource" />
</bean>

Per my finding there is no view available for XLSX export in Spring? Does anyone what is the solution/other way to achieve this, other than using JRXlsAbstractExporter and changing the implementation (which I have seen in other forums being referred by many as solution).

Thanks in advance,

Ashish

like image 984
user1250669 Avatar asked Dec 03 '25 16:12

user1250669


1 Answers

When looking for the answer for this, I found this 18 months old unanswered question. This probably means we need to roll our own. This seems to work:

Definition:

<bean id="xlsxReport" class="com.foo.bar.report.JasperReportsXlsxView" p:url="classpath:reports/foobar.jrxml"/>

And the class:

public class JasperReportsXlsxView extends AbstractJasperReportsSingleFormatView {

    @Override
    protected JRExporter createExporter() {
        return new JRXlsxExporter();
    }

    @Override
    protected boolean useWriter() {
        return false;
    }

    public JasperReportsXlsxView() {
        setContentType("application/vnd.ms-excel");
    }
}
like image 194
Mzzl Avatar answered Dec 06 '25 17:12

Mzzl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!