poi解析word

读取文件所有内容

import org.apache.poi.ooxml.POIXMLDocument;
import org.apache.poi.ooxml.extractor.POIXMLTextExtractor;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * @author: ThinkPad
 * @date: 2021/11/19 11:27
 * @description:
 */
public class WordTest {
   
    /**
     * 读取doc文件内容
     *
     * @param
     * @return 返回文件内容
     * @throws IOException
     */
    public static String doc2String(FileInputStream fs) throws IOException {
   
        String path = "C:\\Users\\Administrator\\Desktop\\11-17\\NA7029 Order Details.docx";
        OPCPackage opcPackage = POIXMLDocument.openPackage(path);
        POIXMLTextExtractor extractor = new XWPFWordExtractor(opcPackage);
        String buffer = extractor.getText();
        System.out.println(buffer);
        extractor.close();
        return null;
    }
    public static String doc2String(File file) throws IOException {
   
        return doc2String(new FileInputStream(file));
    }

    public static void main(String[] args) {
   
        File file = new File("C:\\Users\\Administrator\\Desktop\\11-17\\NA7029 Order Details.docx");
        try {
   
            System.out.println(doc2String(file));
        } catch (IOException e) {
   
            e.printStackTrace();
        }
    }

}

读取文件中所有表格及其内容

package com.chenmei.util;

import com.chenmei.bean.ExcelAll;
import com.chenmei.bean.ExcelNotes;
import com.chenmei.bean.ExeclOrder;
import com.chenmei.bean.ExeclTop;
import org.apache.poi.ooxml.POIXMLDocument;
import org.apache.poi.ooxml.extractor.POIXMLTextExtractor;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;

import java.io.FileInputStream;
import java.util.*;

import static java.util.stream.Collectors.toMap;

/**
 * @author: ThinkPad
 * @date: 2021/9/26 14:09
 * @description:
 */
public class WordUtil {
   
    public ExcelAll getWord(String filePath){
   
    HashMap<String, String> materialMap = new HashMap<String, String>() {
   {
   
            put("Pine", "松木");
            put("Basswood", "椴木");
            put("Poly", "PVC");
            put("Waterproof Poly", "PVC");
            put("White Ash", "水曲柳");
            put("Abachi", "阿尤斯");
            put("Paulownia", "桐木");
        }};
        HashMap<String, String> installationStyleMap = new HashMap<String, String>() {
   {
   
            put("Full height", "Full height(全部高度)");
            put("Café Style", "Café Style");
            put("T on T without T-Post", "T on T without T-Post (双层窗没有加T型柱)");
            put("By pass track system", "By pass track system (推拉窗)");
            put("Bi Fold track system", "Bi Fold track system(折叠窗)");
            put("Shaped shutters", "Shaped shutters(异形窗)");
        }};
        HashMap<String, String> inOrOutOfRecessMap = new HashMap<String, String>() {
   {
   
            put("Inside", "Inside(内装)");
            put("Outside", "Outside(外装)");
        }};
        HashMap<String, String> colourMap = new HashMap<String, String>() {
   {
   
            put(
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值