我正在使用jasperreports 3.5.3生成一个大型(但简单的)报告。只有一个带字符串的表。
当我列出足够大的选择时,生成的文件已损坏。 Excel会警告用户,并且某些数据已损坏。但是,如果我过滤数据以显示某些行,包括正常生成的行。
有人对此损坏的Excel文件结果有经验吗?
提示:它发生在Linux / Apache + JBoss服务器上,但本地Windows / Jboss上的相同代码可以正常工作。我不认为中间的Apache有事可做。它必须是一代人自己的东西。
答案 0 :(得分:2)
似乎jasperreports 3.5.3可以使用两种“excel编写者”。默认情况下,导出器为JRXlsExporter
,并且对大文件不起作用(至少在我的Spring MVC项目中)。
解决方法是使用基于JExcelAPI的其他导出器。我可以毫不费力地导出数据。
为了使 jasperreport将JExcelAPI用于Spring MVC安装,您必须编写一个个性化的类。它非常简单:
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;
}
}
您需要来自JExcelAPI 2.6发行版的类路径中的jxl.jar。