我无法解决这个问题。来源是:
try {
// 1) Load Docx file by filling Velocity template engine and cache it to the registry
InputStream in = new FileInputStream("/test.docx");
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in,TemplateEngineKind.Velocity);
// 2) Create context Java model
IContext context = report.createContext();
context.put("user", variables.get("user"));
// 3) Generate report by merging Java model with the Docx
OutputStream out = new FileOutputStream(new File("/test_Out.docx"));
report.process(context, out);
} catch (IOException e) {
e.printStackTrace();
} catch (XDocReportException e) {
e.printStackTrace();
}
当我尝试执行此代码时,出现错误:
09:03:15,608 ERROR [stderr] (http--127.0.0.1-8080-1) fr.opensagres.xdocreport.core.XDocReportException: Impossible to create report for the input stream. The report loader supports only [] files type.
09:03:15,608 ERROR [stderr] (http--127.0.0.1-8080-1) at fr.opensagres.xdocreport.document.registry.XDocReportRegistry.createReport(XDocReportRegistry.java:328)
09:03:15,608 ERROR [stderr] (http--127.0.0.1-8080-1) at fr.opensagres.xdocreport.document.registry.XDocReportRegistry.createReport(XDocReportRegistry.java:313)
09:03:15,608 ERROR [stderr] (http--127.0.0.1-8080-1) at fr.opensagres.xdocreport.document.registry.XDocReportRegistry.loadReport(XDocReportRegistry.java:285)
09:03:15,608 ERROR [stderr] (http--127.0.0.1-8080-1) at fr.opensagres.xdocreport.document.registry.XDocReportRegistry.loadReport(XDocReportRegistry.java:278)
09:03:15,608 ERROR [stderr] (http--127.0.0.1-8080-1) at fr.opensagres.xdocreport.document.registry.XDocReportRegistry.loadReport(XDocReportRegistry.java:264)
它指向这一行:
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in,TemplateEngineKind.Velocity);
这是什么意思-报表加载器仅支持[]文件类型。
从InputStream加载数据有什么问题吗?
我不知道该如何解决。请帮忙!
最佳答案
您的错误意味着您的类路径中没有XDocReport fr.opensagres.xdocreport.document.docx docx实现JAR。我建议您阅读Docx Reporting,它解释了该内容,而XDocReport download samples包含了您希望做的很好的JAR(使用Velocity / Freemarker,由ODT,Docx生成)。
关于java - xDocReport-不可能为输入流创建报告,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9938541/