zoukankan      html  css  js  c++  java
  • java POI解析word为文本内容

    package com.github.tangyi.exam.service;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import org.apache.poi.POIXMLTextExtractor;
    import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
    import org.apache.poi.xwpf.usermodel.XWPFDocument;
    
    public class TestWord {
    
        public static void main(String[] args) {
            File file = new File("E:\yaoyu\exam\秦洲试题单选.docx");
            file = new File("E:\yaoyu\exam\医疗单选整合后带答案 (自动保存的).docx");
            XWPFDocument doc = null;
            POIXMLTextExtractor extractor = null;
            try {
                doc = new XWPFDocument(new FileInputStream(file));
                extractor = new XWPFWordExtractor(doc);
                String content = extractor.getText();
                System.out.println(content);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    if (doc != null) {
                        doc.close();
                    }
                    if (extractor != null) {
                        extractor.close();
                    }
                } catch (IOException e) {
                }
            }
        }
    
    }
    

      

  • 相关阅读:
    Wannafly挑战赛9
    acm之图论基础
    Codeforces Round #459 (Div. 2)
    Codeforces Round #460 (Div. 2)
    浙南联合训练赛20180129
    AtCoder Regular Contest 090
    牛客练习赛11
    2018年1月26日天梯赛练习1
    csa Round #66 (Div. 2 only)
    EOJ Monthly 2018.1
  • 原文地址:https://www.cnblogs.com/yaoyu1983/p/13082280.html
Copyright © 2011-2022 走看看