我想做一些文档转换工作使用jodconverter & open office 4。我已经在Windows7上的C:\Program Files (X86)\OpenOffice4中安装了open office。在任务管理器中,我看到了soffice.bin*32的过程
当我运行我的演示程序将doc文件转换为html文件时。我遇到了这样的异常:
log4j:WARN No appenders could be found for logger (org.artofsolving.jodconverter.office.OfficeManager).
log4j:WARN Please initialize the log4j system properly.
一月 07, 2016 10:27:49 上午 org.artofsolving.jodconverter.office.OfficeConnection connect
信息: connected: 'socket,host=127.0.0.1,port=8100,tcpNoDelay=1'
Exception in thread "main" org.artofsolving.jodconverter.office.OfficeException: could not load document: asdf.doc
at org.artofsolving.jodconverter.AbstractConversionTask.loadDocument(AbstractConversionTask.java:93)
at org.artofsolving.jodconverter.AbstractConversionTask.execute(AbstractConversionTask.java:53)
at org.artofsolving.jodconverter.office.ExternalOfficeManager.execute(ExternalOfficeManager.java:70)
at org.artofsolving.jodconverter.OfficeDocumentConverter.convert(OfficeDocumentConverter.java:72)
at org.artofsolving.jodconverter.OfficeDocumentConverter.convert(OfficeDocumentConverter.java:63)
at demo.OfficeDocumentManager.conveterOfficeDocument(OfficeDocumentManager.java:84)
at demo.Test.main(Test.java:9)我检查了jodconverter的源代码:
private XComponent loadDocument(OfficeContext context, File inputFile) throws OfficeException {
if (!inputFile.exists()) {
throw new OfficeException("input document not found");
}
XComponentLoader loader = cast(XComponentLoader.class, context.getService(SERVICE_DESKTOP));
Map<String,?> loadProperties = getLoadProperties(inputFile);
XComponent document = null;
try {
document = loader.loadComponentFromURL(toUrl(inputFile), "_blank", 0, toUnoProperties(loadProperties));
} catch (IllegalArgumentException illegalArgumentException) {
throw new OfficeException("could not load document: " + inputFile.getName(), illegalArgumentException);
} catch (ErrorCodeIOException errorCodeIOException) {
throw new OfficeException("could not load document: " + inputFile.getName() + "; errorCode: " + errorCodeIOException.ErrCode, errorCodeIOException);
} catch (IOException ioException) {
throw new OfficeException("could not load document: " + inputFile.getName(), ioException);
}
if (document == null) {
throw new OfficeException("could not load document: " + inputFile.getName());
}
return document;
}当我调试这些代码时。我发现文档总是为空。我想在这里加载的文件是存在的并且是可读的。谁能告诉我为什么我不能加载文件??
发布于 2016-01-12 15:36:35
我现在可以结束这个问题,当你遇到这个问题时,你可以重新保存你的文档,然后重试。我认为这是因为文档的内部错误使XComponentLoader返回null。
https://stackoverflow.com/questions/34646700
复制相似问题