zoukankan      html  css  js  c++  java
  • 《《《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 }
  • 相关阅读:
    php 学习笔记 数组2
    php 学习笔记 数组1
    jQuery prop 全选和全不全
    jquery获取多个checkbox的值异步提交给php
    php 计算多维数组中所有值的总和
    系统状态码原型
    hadoop win10开发环境
    kafka spring整合版本匹配
    mac 安装brew
    hadoop2.8.5 idea2019.1.3插件安装
  • 原文地址:https://www.cnblogs.com/lidar/p/12708176.html
Copyright © 2011-2022 走看看