Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在android中将office文档转换为html_Java_Android_Apache Poi_Docx4j - Fatal编程技术网

Java 如何在android中将office文档转换为html

Java 如何在android中将office文档转换为html,java,android,apache-poi,docx4j,Java,Android,Apache Poi,Docx4j,我们可以在Android中将microsoft office文档(doc、docx、ppt、pptx、xls、xlsx等)转换为html字符串吗。 我需要在我的应用程序中显示office文档。我已经搜索并找到了docx4j、ApachePOI和html格式的转换文件。这种方法在桌面版本中运行良好。但在安卓系统中使用时,我发现“无法转换为Dalvik格式错误1”。这可能是因为在我的android项目中使用了太多的JAR。 我想知道是否有一种方法可以在android中将office文档转换为html

我们可以在Android中将microsoft office文档(doc、docx、ppt、pptx、xls、xlsx等)转换为html字符串吗。 我需要在我的应用程序中显示office文档。我已经搜索并找到了docx4j、ApachePOI和html格式的转换文件。这种方法在桌面版本中运行良好。但在安卓系统中使用时,我发现“无法转换为Dalvik格式错误1”。这可能是因为在我的android项目中使用了太多的JAR。 我想知道是否有一种方法可以在android中将office文档转换为html。 对不起英语

编辑

我现在能够使用ApachePOI将文档转换为html。 这里有一个方法

public void showsimpleWord() {
    File file = new File("/sdcard/test.doc");

    HWPFDocumentCore wordDocument = null;
    try {
        wordDocument = WordToHtmlUtils.loadDoc(new FileInputStream(file));
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    WordToHtmlConverter wordToHtmlConverter = null;
    try {
        wordToHtmlConverter = new WordToHtmlConverter(
                DocumentBuilderFactory.newInstance().newDocumentBuilder()
                        .newDocument());
        wordToHtmlConverter.processDocument(wordDocument);
        org.w3c.dom.Document htmlDocument = wordToHtmlConverter
                .getDocument();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DOMSource domSource = new DOMSource(htmlDocument);
        StreamResult streamResult = new StreamResult(out);
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer serializer = tf.newTransformer();
        serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        serializer.setOutputProperty(OutputKeys.INDENT, "yes");
        serializer.setOutputProperty(OutputKeys.METHOD, "html");
        serializer.transform(domSource, streamResult);
        out.close();
        String result = new String(out.toByteArray());
        System.out.println(result);
        ((WebView) findViewById(R.id.webview)).loadData(result,
                "text/html", "utf-8");

    } catch (Exception e) {
        e.printStackTrace();
    }
}

现在正在搜索其他文档。

虽然像其他人提到的那样,在android设备上可以将word文档转换为HTML,但由于一系列问题,这是不可取的。(即android的处理能力和内存有限,以及与大多数设计用于处理MS Office文件的库的兼容性问题)正如他们所提到的,最好在服务器端进行转换。也就是说,如果你的情况真的不可能,你可能想看看

询问者似乎也有类似的问题。(假设我正确理解了你的问题)海报在讨论的中途回答了他们自己的问题,并在他自己的答案的评论中提供了一个链接到他的来源。他在他的解决方案中使用了Apachi POI库,但将库分解为几个较小的DEX文件(库的每个组件一个),以便与android配合使用


希望这是有帮助的

有必要在设备端执行此操作吗?也许使用服务器进行这些转换会更好?@RafaelOsipov不,如果我们使用服务器进行转换。我们的应用程序将依赖于internet连接。在这种情况下,使用Apache POI在服务器上实现转换引擎,设备将只向服务器发送文档并接收转换结果。@RafaelOsipov感谢您对我的问题的关注。实际上,在我们的应用程序中,要求在应用程序中显示office文档。即使我们处于脱机状态。是否将文件发送到服务器进行渲染,然后缓存结果以供脱机查看?