• 《《《java代码读取word文档》》》


    参考网址 http://www.2cto.com/kf/201701/584974.html

     1 package com.demo.test;
     2 
     3 import org.apache.poi.hwpf.extractor.WordExtractor;
     4 
     5 import java.io.File;
     6 import java.io.FileInputStream;
     7 import java.io.FileNotFoundException;
     8 import java.io.IOException;
     9 
    10 public class readWord {
    11 
    12     public static void main(String[] args) {
    13         ExportDocImpl test = new ExportDocImpl();
    14         //String filePath="E:\java导入word表格.doc";
    15         String filePath="E:\java导入word表格.docx";
    16 //        test.testWord(filePath);
    17         getTextFromWord(filePath);
    18     }
    19     /**
    20      *
    21      * @Title: getTextFromWord
    22      * @Description: 读取word
    23      * @param filePath
    24      *            文件路径
    25      * @return: String 读出的Word的内容
    26      */
    27     public static String getTextFromWord(String filePath) {
    28         String result = null;
    29 //        filePath="E:\java导入word表格.docx";
    30         File file = new File(filePath);
    31         FileInputStream fis = null;
    32         try {
    33             fis = new FileInputStream(file);
    34             @SuppressWarnings("resource")
    35             WordExtractor wordExtractor = new WordExtractor(fis);
    36             result = wordExtractor.getText();
    37             System.err.println("result"+ "========================= "+result);
    38         } catch (FileNotFoundException e) {
    39             e.printStackTrace();
    40         } catch (IOException e) {
    41             e.printStackTrace();
    42         } finally {
    43             if (fis != null) {
    44                 try {
    45                     fis.close();
    46                 } catch (IOException e) {
    47                     e.printStackTrace();
    48                 }
    49             }
    50         }
    51         return result;
    52     }
    53 }
  • 相关阅读:
    20170417成员运算符、身份运算符、布尔运算符
    20170417学习find、replace、abs三个函数
    shell 双中括号 双小括号
    man 命令
    awk 命令-对文本和数据进行处理
    shell-1-day
    shell---0-day
    /etc
    Selenium IDE使用
    python 自动化测试框架 pytest 和unittest 的区别
  • 原文地址:https://www.cnblogs.com/lidar/p/12708176.html
Copyright © 2020-2023  润新知