【问题标题】:How to extract plain text from a DOCX file using the new OOXML support in Apache POI 3.5?如何使用 Apache POI 3.5 中新的 OOXML 支持从 DOCX 文件中提取纯文本?
【发布时间】:2009-09-29 14:00:32
【问题描述】:

2009 年 9 月 28 日,Apache POI project 发布了 3.5 版,正式支持 Office 2007 中引入的 OOXML 格式,如 DOCX 和 XLSX。

请提供一个代码示例,用于以纯文本格式提取 DOCX 文件的内容,忽略任何样式或格式。

我之所以问这个问题是因为我找不到任何涵盖新 OOXML 支持的 Apache POI 示例。

【问题讨论】:

    标签: docx apache-poi openxml xlsx


    【解决方案1】:

    这对我有用。确保添加所需的 jars(升级 xmlbeans 等)

    public String extractText(InputStream in) throws Exception {
        XWPFDocument doc = new XWPFDocument(in);
        XWPFWordExtractor ex = new XWPFWordExtractor(doc);
        String text = ex.getText();
        return text;
    }
    

    【讨论】:

      【解决方案2】:

      这个比较通用

      POITextExtractor poitex = ExtractorFactory.createExtractor(in);

      返回 poitex.getText();

      【讨论】:

      • 我同意。感谢您提供涵盖更通用文本提取的好答案。我希望我能同时接受。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-27
      • 1970-01-01
      • 1970-01-01
      • 2011-08-06
      • 1970-01-01
      • 2013-05-30
      • 2014-10-03
      相关资源
      最近更新 更多