【问题标题】:how to read the formated text as a html text from ms word(.doc) using poi?如何使用 poi 从 ms word(.doc) 读取格式化文本作为 html 文本?
【发布时间】:2013-06-13 05:35:44
【问题描述】:

我想将格式化文本读取为 html 文本,例如 (boldvalue) 我还想使用图像标签链接获取图像.我正在使用 poi poi 是否可以选择以 html 格式获取此类数据?

【问题讨论】:

  • 我如何从图像标签中获取图像
  • 图像标签带有注释行,css 也包含在一个类中,但我想要标签中的 css,例如 。如何获得这个

标签: java apache-poi


【解决方案1】:

试试这个

HWPFDocumentCore wordDocument = WordToHtmlUtils.loadDoc(new FileInputStream("D:\\temp\\seo\\1.doc"));

        WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(
                DocumentBuilderFactory.newInstance().newDocumentBuilder()
                        .newDocument());
        wordToHtmlConverter.processDocument(wordDocument);
        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);

【讨论】:

  • 这是从副本中逐字复制的吗?
  • 它返回 html 值,但样式是作为类来的,而不是我如何使用这样的标签获取样式()。跨度>
  • 如何获取图片标签和图片
猜你喜欢
  • 2011-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-24
相关资源
最近更新 更多