繁体   English   中英

将报告导出到docx时Jasper报告错误

[英]Jasper report error when exporting report to docx

我正在尝试将jasper报告导出到.docx文件。 但我收到这个错误

java.lang.ClassCastException: java.lang.String cannot be cast to net.sf.jasperreports.engine.JasperPrint

我正在使用Java开发此程序。

这是我使用的代码

public void generateReport2() throws PrinterException {

try {  
String sourceFileName = "src/POS_bill/esFourReport.jasper";
String printFileName = null;
DataBeanFactory2 DataBean = new DataBeanFactory2();
JRBeanCollectionDataSource beanColDataSource = new      JRBeanCollectionDataSource(DataBean.generateCollection());
Map parameters = new HashMap();
printFileName = JasperFillManager.fillReportToFile(
     sourceFileName,
     parameters,
     beanColDataSource);


JRDocxExporter exp=new JRDocxExporter();   
exp.setParameter(JRExporterParameter.JASPER_PRINT,printFileName);
exp.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,"src/POS_bill/sample_report2.docx");
exp.exportReport();


} catch (Exception e) {

System.out.println(e);
} 
}

终于我找到了答案!

我删除了这两行

exp.setParameter(JRExporterParameter.JASPER_PRINT,printFileName);
exp.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,"src/POS_bill/sample_report2.docx");

并用这些替换

exporter.setExporterInput(new SimpleExporterInput(printFileName));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("src/POS_bill/samplereport2.docx"));

现在工作正常!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM