1.读取word文档中标题和表格(支持2007版本及以上的版本),将代码的docx改为doc则可读doc结尾的文档
代码如下:
package read;
import java.io.FileInputStream;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.xwpf.usermodel.*;
/**
* 读取word文档中标题和表格(支持2007版本及以上的版本),将代码的docx改为doc则可读doc结尾的文档
*
*/
public class ExportDoc2 {
public static void main(String[] args) {
String filePath ="G:\\new\\行动简报.docx";
testWord(filePath);
}
/**
* 读取文档中表格
* @param filePath
*/
public static void testWord(String filePath){
try{
FileInputStream in = new FileInputStream(filePath);//载入文档
// 处理docx格式 即office2007以后版本
if(filePath.toLowerCase().endsWith("docx")){
//word 2007 图片不会被读取, 表格中的数据会被放在字符串的最后
XWPFDocument xwpf = new XWPFDocument(in)