poi解析word中的表格

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/nongminkouhao/article/details/84377832

解析word简历,使用poi解析word表格研究记录如下:

package poi;
 
import java.io.File;
import java.io.FileInputStream;
import java.util.List;

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;
 
public class TestPoi {
	/**
	 * 读取word文件内容
	 * @param path
	 * @return buffer
	 */
	public String readWord(String path) {
		String buffer = "";
		try {
			if (path.endsWith(".doc")) {
				XWPFDocument xdoc = new XWPFDocument(new FileInputStream(new File(path)));
			    List<XWPFTable> tables = xdoc.getTables();
			    for (XWPFTable table : tables) {
			        // 获取表格的行
			        List<XWPFTableRow> rows = table.getRows();
			        for (XWPFTableRow row : rows) {
			            // 获取表格的每个单元格
			            List<XWPFTableCell> tableCells = row.getTableCells();
			            for (XWPFTableCell cell : tableCells) {
			                 // 获取单元格的内容
			                 String text1 = cell.getText();
			                 System.out.println(text1);
			            }
			        }
			    }
			} else if (path.endsWith("docx")) {
			} else {
				System.out.println("此文件不是word文件!");
			}
 
		} catch (Exception e) {
			e.printStackTrace();
		}
 
		return buffer;
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		TestPoi tp = new TestPoi();
		String content = tp.readWord("D:\\test01.doc");
		System.out.println("content===="+content);
	}
 
}

word表格如下:
简历示例
解析结果如下:

姓名:test
性别:男|_|      女|_|
出生日期:(    9月/    1日/      2018年)
居住地址:上海
户籍地:上海
籍贯:上海
出生地:上海
身份证号码:321111199102043421
民族:汉
政治面貌:党员
手机:18916195870
电子信箱:[email protected]
婚姻状况:未婚
身高/体重:66kg
紧急联系人(关系)及电话:18516601111
教育经历
日期
院校名称
专业
学历
是否全日制

(年/月/日)





2018年  1月  1日至   2018年  12月  12日
清华
软件
本科
是

2017年  1月  1日至   2017年  12月  12日
北大
软件
本科
是
职称/资格证书
学士学位证
工作经历
时间(年/月/日)
公司名称
职位
月薪总额
工作国家及城市

2017年  1月  1日至   2017年  12月  12日
新致1
软件1
8888
上海1

2018年  1月  1日至   2018年  12月  12日
新致2
软件2
9999
上海2
能否接受异地工作:
时
可接受异地工作地区或城市:
上海
家庭成员
姓名
关系
所在单位
联系电话

父亲
父子
无业
13988888888

母亲
母子
无业
13788888888
content====

仅此记录,希望对看到的朋友有帮助

猜你喜欢

转载自blog.csdn.net/nongminkouhao/article/details/84377832