我正在测试XDocReport中的示例代码。我结合起来,根据docx模板创建了docx和pdf报告。但是我继续收到这条消息
Apr 21, 2016 5:39:10 PM fr.opensagres.xdocreport.converter.ConverterRegistry internalFindConverter
SEVERE: Cannot find converters from=DOCX
fr.opensagres.xdocreport.converter.XDocConverterException: Cannot find converters from=DOCX
at fr.opensagres.xdocreport.converter.ConverterRegistry.internalFindConverter(ConverterRegistry.java:121)
at fr.opensagres.xdocreport.converter.ConverterRegistry.findConverter(ConverterRegistry.java:74)
at fr.opensagres.xdocreport.document.AbstractXDocReport.getConverter(AbstractXDocReport.java:667)
at fr.opensagres.xdocreport.document.AbstractXDocReport.convert(AbstractXDocReport.java:690)
at fr.opensagres.xdocreport.samples.docxandfreemarker.DocxProjectWithFreemarkerList.main(DocxProjectWithFreemarkerList.java:231)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
以下是代码:
try
{
InputStream in = DocxProjectWithFreemarker.class.getResourceAsStream( "DocxProjectWithFreemarkerList.docx" );
IXDocReport report = XDocReportRegistry.getRegistry().loadReport( in, TemplateEngineKind.Freemarker );
FieldsMetadata metadata = report.createFieldsMetadata();
metadata.load( "developers", Developer.class, true );
IContext context = report.createContext();
Project project = new Project( "XDocReport" );
context.put( "project", project );
List<Developer> developers = new ArrayList<Developer>();
developers.add( new Developer( "ZERR", "Angelo", "angelo.zerr@gmail.com" ) );
developers.add( new Developer( "Leclercq", "Pascal", "pascal.leclercq@gmail.com" ) );
context.put( "developers", developers );
OutputStream out = new FileOutputStream( new File( "DocxProjectWithFreemarkerList_Out.docx" ) );
report.process( context, out );
// ===========================================================================================
Options options = Options.getTo(ConverterTypeTo.PDF);
OutputStream outt = new FileOutputStream(new File("DocxProjectWithFreemarkerList_Out.pdf"));
report.convert(context, options, outt);
}
catch ( IOException e )
{
e.printStackTrace();
}
catch ( XDocReportException e )
{
e.printStackTrace();
}
代码有什么问题吗?我该如何解决这个错误?
答案 0 :(得分:4)
您的问题与this issue相同。
您需要在类路径中包含 fr.opensagres.xdocreport.converter.docx.xwpf JAR及其依赖项JAR(iText等)。