org.artofsolving.jodconverter.office.OfficeException:无法加载文档:asdf.doc

时间:2016-01-07 03:00:36

标签: jodconverter

我想做一些文件转换工作使用jodconverter&开放办公室4。 我在Windows 7的C:\ Program Files(x86)\ OpenOffice 4上安装了开放式办公室。 在任务mgr我看过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;
    }

当我调试这些代码时。我发现文件总是空的。我想在这里加载的文件是存在且可读的。任何人都告诉我为什么我无法加载文件?

1 个答案:

答案 0 :(得分:0)

我现在可以关闭这个问题,当你提出这个问题时,你可以重新保存你的文档,然后重试。我认为这是因为使XComponentLoader的文档的内部错误返回null。