import java.io.File;
import java.io.FileInputStream;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.fileupload.disk.DiskFileItem;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.hwpf.usermodel.Table;
import org.apache.poi.hwpf.usermodel.TableCell;
import org.apache.poi.hwpf.usermodel.TableIterator;
import org.apache.poi.hwpf.usermodel.TableRow;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
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 org.jeecgframework.core.util.StringUtil;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
/*
*/
/**
* 读取word 2007
* 根据word 的行来读取,
* 对应于每行不同的列, 及类型, 使用不同的方法解析 , 返回对应的集合
*/
public class ImortWordUtil {
public static void main(String[] args) {
// ImortWordUtil test = new ImortWordUtil();
// String filePath = "C:\\Users\\Lenovo\\Desktop\\test\\任免审批表_xxx.docx";
// test.wordWork2(filePath);
//String filePath="E:\\java导入word表格.doc";
// String filePath="C:\\Users\\Lenovo\\Desktop\\test\\87.中层干部履历表(xxx).docx";
// test.testWord(filePath);
}
//========================================================================================================================================
// word 导入 , 模板一
//========================================================================================================================================
/**
* 返回职员信息
* @param file
* @return
*/
public List<List<Map<String,String>>> wordEmp(MultipartFile file){
// 职员基本信息
List<List<Map<String,String>>> li = new LinkedList<>();
// 工作经历 列表头
List<String> lists = null;
// 家庭信息 列表头
List<String> lists2 = null;
// 家庭信息
List<List<Map<String,String>>> lists3 = new LinkedList<>();
// 工作经历
List<List<List<Map<String,String>>>> lists4 = new LinkedList<>();
try{
//===========================================================================================================
// 会在项目的根目录的临时文件夹下生成一个文件; 未解决 MultipartFile 转化为 File, 此方法有缺点
//===========================================================================================================
CommonsMultipartFile cf= (CommonsMultipartFile)file;
DiskFileItem fi = (DiskFileItem)cf.getFileItem();
File f = fi.getStoreLocation();
FileInputStream in = new FileInputStream(f);//载入文档
//如果是office2007 docx格式
// if(filePath.toLowerCase().endsWith("docx")){
//word 2007 图片不会被读取, 表格中的数据会被放在字符串的最后
XWPFDocument xwpf = new XWPFDocument(in);//得到word文档的信息
// List<XWPFParagraph> listParagraphs = xwpf.getParagraphs();//得到段落信息
Iterator<XWPFTable> it = xwpf.getTablesIterator();//得到word中的表格
while(it.hasNext()){
XWPFTable table = it.next();
List<XWPFTableRow> rows=table.getRows();
//读取每一行数据
for (int i = 0; i < rows.size(); i++) {
XWPFTableRow row = rows.get(i);
//读取每一列数据
List<XWPFTableCell> cells = row.getTableCells();
// 控制行数据
if(i == 0 || i == 1 || i == 2){
List<Map<String,String>> list = this.ImplCell7(cells);
li.add(list);
}else if(i == 3 || i == 4){
List<Map<String,String>> list = this.ImplCell4(cells);
li.add(list);
}else if(i == 5 || i == 6){
List<Map<String,String>> list = this.ImplCell6(cells);
li.add(list);
}else if(i == 7){
List<Map<String,String>> list = this.ImplCell2(cells);
li.add(list);
}else if(i == 8){
// 列表表头
lists = this.ImplCellList(cells);
}else if(i == 9 || i == 10 || i == 11){
List<List<Map<String,String>>> list = this.ImplCellList2(lists,cells);
if(list.size() > 0){
lists4.add(list);
}
}else if(i == 12 || i == 13){
// 学历教育简历 和 非学历学位培训情况
continue;
}else if(i == 14){
// 奖惩情况
List<Map<String,String>> list = this.ImplCell2(cells);
li.add(list);
}else if(i== 15){
// 列表表头
lists2 = this.ImplCellList3(cells);
}else{
for(int z = 0 ; z < cells.size() ; z++){
if(z == 0){
String str = cells.get(z).getText();
String st = StringUtil.replaceBlank(str);
if(StringUtil.equals(st,"家庭住址")){
List<Map<String,String>> list = this.ImplCell2(cells);
li.add(list);
}else if(StringUtil.equals(st,"其他需要说明情况")){
List<Map<String,String>> list = this.ImplCell2(cells);
li.add(list);
}else {
List<Map<String,String>> list = this.ImplCellList4(lists2,cells);
lists3.add(list);
}
}
}
}
}
}
// }
/*
else{
//如果是office2003 doc格式
POIFSFileSystem pfs = new POIFSFileSystem(in);
HWPFDocument hwpf = new HWPFDocument(pfs);
Range range = hwpf.getRange();//得到文档的读取范围
TableIterator it = new TableIterator(range);
//迭代文档中的表格
while (it.hasNext()) {
Table tb = (Table) it.next();
//迭代行,默认从0开始
for (int i = 0; i < tb.numRows(); i++) {
TableRow tr = tb.getRow(i);
//迭代列,默认从0开始
for (int j = 0; j < tr.numCells(); j++) {
TableCell td = tr.getCell(j);//取得单元格
//取得单元格的内容
for(int k=0;k<td.numParagraphs();k++){
Paragraph para =td.getParagraph(k);
String s = para.text();
//去除后面的特殊符号
if(null!=s&&!"".equals(s)){
s=s.substring(0, s.length()-1);
}
System.out.println(i + "行 ," + j + "列 ," + k + "单元格 ," + s);
}
}
}
}
}
*/
}catch(Exception e){
e.printStackTrace();
}
return li;
}
/**
* 返回家庭信息
* @param
* @return
*/
public List<List<Map<String,String>>> wordFamily(MultipartFile file){
// 职员基本信息
List<List<Map<String,String>>> li = new LinkedList<>();
// 工作经历 列表头
List<String> lists = null;
// 家庭信息 列表头
List<String> lists2 = null;
// 家庭信息
List<List<Map<String,String>>> lists3 = new LinkedList<>();
// 工作经历
List<List<List<Map<String,String>>>> lists4 = new LinkedList<>();
try{
//===========================================================================================================
// 会在项目的根目录的临时文件夹下生成一个文件; 未解决 MultipartFile 转化为 File, 此方法有缺点
//===========================================================================================================
CommonsMultipartFile cf= (CommonsMultipartFile)file;
DiskFileItem fi = (DiskFileItem)cf.getFileItem();
File f = fi.getStoreLocation();
FileInputStream in = new FileInputStream(f);//载入文档
//如果是office2007 docx格式
// if(filePath.toLowerCase().endsWith("docx")){
//word 2007 图片不会被读取, 表格中的数据会被放在字符串的最后
XWPFDocument xwpf = new XWPFDocument(in);//得到word文档的信息
// List<XWPFParagraph> listParagraphs = xwpf.getParagraphs();//得到段落信息
Iterator<XWPFTable> it = xwpf.getTablesIterator();//得到word中的表格
while(it.hasNext()){
XWPFTable table = it.next();
List<XWPFTableRow> rows=table.getRows();
//读取每一行数据
for (int i = 0; i < rows.size(); i++) {
XWPFTableRow row = rows.get(i);
//读取每一列数据
List<XWPFTableCell> cells = row.getTableCells();
// 控制行数据
if(i == 0 || i == 1 || i == 2){
List<Map<String,String>> list = this.ImplCell7(cells);
li.add(list);
}else if(i == 3 || i == 4){
List<Map<String,String>> list = this.ImplCell4(cells);
li.add(list);
}else if(i == 5 || i == 6){
List<Map<String,String>> list = this.ImplCell6(cells);
li.add(list);
}else if(i == 7){
List<Map<String,String>> list = this.ImplCell2(cells);
li.add(list);
}else if(i == 8){
// 列表表头
lists = this.ImplCellList(cells);
}else if(i == 9 || i == 10 || i == 11){
List<List<Map<String,String>>> list = this.ImplCellList2(lists,cells);
if(list.size() > 0){
lists4.add(list);
}
}else if(i == 12 || i == 13){
// 学历教育简历 和 非学历学位培训情况
continue;
}else if(i == 14){
// 奖惩情况
List<Map<String,String>> list = this.ImplCell2(cells);
li.add(list);
}else if(i== 15){
// 列表表头
lists2 = this.ImplCellList3(cells);
}else{
for(int z = 0 ; z < cells.size() ; z++){
if(z == 0){
String str = cells.get(z).getText();
String st = StringUtil.replaceBlank(str);
if(StringUtil.equals(st,"家庭住址")){
List<Map<String,String>> list = this.ImplCell2(cells);
li.add(list);
}else if(StringUtil.equals(st,"其他需要说明情况")){
List<Map<String,String>> list = this.ImplCell2(cells);
li.add(list);
}else {
List<Map<String,String>> list = this.ImplCellList4(lists2,cells);
lists3.add(list);
}
}
}
}
}
}
// }
/*
else{
//如果是office2003 doc格式
POIFSFileSystem pfs = new POIFSFileSystem(in);
HWPFDocument hwpf = new HWPFDocument(pfs);
Range range = hwpf.getRange();//得到文档的读取范围
TableIterator it = new TableIterator(range);
//迭代文档中的表格
while (it.hasNext()) {
Table tb = (Table) it.next();
//迭代行,默认从0开始
for (int i = 0; i < tb.numRows(); i++) {
TableRow tr = tb.getRow(i);
//迭代列,默认从0开始
for (int j = 0; j < tr.numCells(); j++) {
TableCell td = tr.getCell(j);//取得单元格
//取得单元格的内容
for(int k=0;k<td.numParagraphs();k++){
Paragraph para =td.getParagraph(k);
String s = para.text();
//去除后面的特殊符号
if(null!=s&&!"".equals(s)){
s=s.substring(0, s.length()-1);
}
System.out.println(i + "行 ," + j + "列 ," + k + "单元格 ," + s);
}
}
}
}
}
*/
}catch(Exception e){
e.printStackTrace();
}
return lists3;
}
/**
* 返回工作经历
* @param
* @return
*/
public List<List<List<Map<String,String>>>> wordWork(MultipartFile file){
// 职员基本信息
List<List<Map<String,String>>> li = new LinkedList<>();
// 工作经历 列表头
List<String> lists = null;
// 家庭信息 列表头
List<String> lists2 = null;
// 家庭信息
List<List<Map<String,String>>> lists3 = new LinkedList<>();
// 工作经历
List<List<List<Map<String,String>>>> lists4 = new LinkedList<>();
try{
//===========================================================================================================
// 会在项目的根目录的临时文件夹下生成一个文件; 未解决 MultipartFile 转化为 File, 此方法有缺点
//===========================================================================================================
CommonsMultipartFile cf= (CommonsMultipartFile)file;
DiskFileItem fi = (DiskFileItem)cf.getFileItem();
File f = fi.getStoreLocation();
FileInputStream in = new FileInputStream(f);//载入文档
//如果是office2007 docx格式
// if(filePath.toLowerCase().endsWith("docx")){
//word 2007 图片不会被读取, 表格中的数据会被放在字符串的最后
XWPFDocument xwpf = new XWPFDocument(in);//得到word文档的信息
// List<XWPFParagraph> listParagraphs = xwpf.getParagraphs();//得到段落信息
Iterator<XWPFTable> it = xwpf.getTablesIterator();//得到word中的表格
while(it.hasNext()){
XWPFTable table = it.next();
List<XWPFTableRow> rows=table.getRows();
//读取每一行数据
for (int i = 0; i < rows.size(); i++) {
XWPFTableRow row = rows.get(i);
//读取每一列数据
List<XWPFTableCell> cells = row.getTableCells();
// 控制行数据
if(i == 0 || i == 1 || i == 2){
List<Map<String,String>> list = this.ImplCell7(cells);
li.add(list);
}else if(i == 3 || i == 4){
List<Map<String,String>> list = this.ImplCell4(cells);
li.add(list);
}else if(i == 5){
List<Map<String,String>> list = this.ImplCell6(cells);
li.add(list);
}else if(i == 6){
List<Map<String,String>> list = this.ImplCell6_(cells);
li.add(list);
}else if(i == 7){
List<Map<String,String>> list = this.ImplCell2(cells);
li.add(list);
}else if(i == 8){
// 列表表头
lists = this.ImplCellList(cells);
}else if(i == 9 || i == 10 || i == 11){
List<List<Map<String,String>>> list = this.ImplCellList2(lists,cells);
if(list.size() > 0){
lists4.add(list);
}
}else if(i == 12 || i == 13){
// 学历教育简历 和 非学历学位培训情况
continue;
}else if(i == 14){
// 奖惩情况
List<Map<String,String>> list = this.ImplCell2(cells);
li.add(list);
}else if(i== 15){
// 列表表头
lists2 = this.ImplCellList3(cells);
}else{
for(int z = 0 ; z < cells.size() ; z++){
if(z == 0){
String str = cells.get(z).getText();
String st = StringUtil.replaceBlank(str);
if(StringUtil.equals(st,"家庭住址")){
List<Map<String,String>> list = this.ImplCell2(cells);
li.add(list);
}else if(StringUtil.equals(st,"其他需要说明情况")){
List<Map<String,String>> list = this.ImplCell2(cells);
li.add(list);
}else {
List<Map<String,String>> list = this.ImplCellList4(lists2,cells);
lists3.add(list);
}
}
}
}
}
}
// }
/*
else{
//如果是office2003 doc格式
POIFSFileSystem pfs = new POIFSFileSystem(in);
HWPFDocument hwpf = new HWPFDocument(pfs);
Range range = hwpf.getRange();//得到文档的读取范围
TableIterator it = new TableIterator(range);
//迭代文档中的表格
while (it.hasNext()) {
Table tb = (Table) it.next();
//迭代行,默认从0开始
for (int i = 0; i < tb.numRows(); i++) {
TableRow tr = tb.getRow(i);
//迭代列,默认从0开始
for (int j = 0; j < tr.numCells(); j++) {
TableCell td = tr.getCell(j);//取得单元格
//取得单元格的内容
for(int k=0;k<td.numParagraphs();k++){
Paragraph para =td.getParagraph(k);
String s = para.text();
//去除后面的特殊符号
if(null!=s&&!"".equals(s)){
s=s.substring(0, s.length()-1);
}
System.out.println(i + "行 ," + j + "列 ," + k + "单元格 ," + s);
}
}
}
}
}
*/
}catch(Exception e){
e.printStackTrace();
}
return lists4;
}
//========================================================================================================================================
// word 导入 , 模板二
//========================================================================================================================================
/**
* 返回职员信息
* @param file
*/
public List<List<Map<String,String>>> wordWork2(MultipartFile file){
// 职员基本信息
List<List<Map<String,String>>> li = new LinkedList<>();
// 简历信息
List<List<Map<String,String>>> resumeList = new LinkedList<>();
// 家庭信息的表头
List<String> lists2 = new LinkedList<>();
// 家庭信息
List<List<Map<String,String>>> lists3 = new LinkedList<>();
try {
//===========================================================================================================
// 会在项目的根目录的临时文件夹下生成一个文件; 未解决 MultipartFile 转化为 File, 此方法有缺点
// //===========================================================================================================
CommonsMultipartFile cf= (CommonsMultipartFile)file;
DiskFileItem fi = (DiskFileItem)cf.getFileItem();
File f = fi.getStoreLocation();
FileInputStream in = new FileInputStream(f);//载入文档
//如果是office2007 docx格式
// if(filePath.toLowerCase().endsWith("docx")){
//word 2007 图片不会被读取, 表格中的数据会被放在字符串的最后
XWPFDocument xwpf = new XWPFDocument(in);//得到word文档的信息
// List<XWPFParagraph> listParagraphs = xwpf.getParagraphs();//得到段落信息
Iterator<XWPFTable> it = xwpf.getTablesIterator();//得到word中的表格
int s = 0;
while(it.hasNext()){
++s;
XWPFTable table = it.next();
List<XWPFTableRow> rows=table.getRows();
// 如果是第一页
if(s == 1){
//读取每一行数据
for (int i = 0; i < rows.size(); i++) {
XWPFTableRow row = rows.get(i);
//读取每一列数据
List<XWPFTableCell> cells = row.getTableCells();
// 第一页的第0行
if(i == 0){
List<Map<String,String>> list = this.ImplCell7_(cells);
li.add(list);
}else if(i == 1 || i == 2){
List<Map<String,String>> list = this.ImplCell7(cells);
li.add(list);
}else if(i == 3){
List<Map<String,String>> list = this.ImplCell4(cells);
li.add(list);
}else if(i == 4){
// 学历学位 最高学历学位
List<Map<String,String>> list = this.ImplCell6(cells);
li.add(list);
}else if(i == 5){
// 学历学位 工作学历学位
List<Map<String,String>> list = this.ImplCell6_(cells);
li.add(list);
}else if(i == 6 || i == 7 || i == 8){
// 职务信息
List<Map<String,String>> list = this.ImplCell2(cells);
li.add(list);
}else {
// 简历内容, 无法确定多少行, 在else中
List<Map<String,String>> list = ImplCellResume2(cells);
if(list.size() > 0){
resumeList.add(list);
}
}
}
}else if(s == 2){
// 如果是第二页,进入这里
// 行 减一 , 不去解析最后一行, ==> 审批机关意见
for (int i = 0; i < rows.size(); i++) {
XWPFTableRow row = rows.get(i);
//读取每一列数据
List<XWPFTableCell> cells = row.getTableCells();
if(i == 0 || i == 1 || i == 2){
List<Map<String,String>> list = ImplCell2(cells);
li.add(list);
}else {
// 家庭信息 及 下面的行
for(int z = 0 ; z < cells.size() ; z++){
if(z == 0){
String str = cells.get(z).getText();
String st = StringUtil.replaceBlank(str);
if(StringUtil.equals(st,"呈报单位")){
List<Map<String,String>> list = ImplCell2_(cells);
li.add(list);
}else if(StringUtil.equals(st,"审批机关意见")){
continue;
}else if(StringUtil.equals(st,"主要家庭成员及社会关系")){
// 家庭信息的表头
lists2 = this.ImplCellList3(cells);
}else {
// 剩下的全是家庭信息
List<Map<String,String>> list = this.ImplCellList4(lists2,cells);
lists3.add(list);
}
}
}
}
}
}
}
}catch (Exception e){
e.printStackTrace();
}
return li;
}
/**
* 返回简历信息
* @param file
*/
public List<List<Map<String,String>>> wordWork2_(MultipartFile file){
// 职员基本信息
List<List<Map<String,String>>> li = new LinkedList<>();
// 简历信息
List<List<Map<String,String>>> resumeList = new LinkedList<>();
// 家庭信息的表头
List<String> lists2 = new LinkedList<>();
// 家庭信息
List<List<Map<String,String>>> lists3 = new LinkedList<>();
try {
//===========================================================================================================
// 会在项目的根目录的临时文件夹下生成一个文件; 未解决 MultipartFile 转化为 File, 此方法有缺点
// //===========================================================================================================
CommonsMultipartFile cf= (CommonsMultipartFile)file;
DiskFileItem fi = (DiskFileItem)cf.getFileItem();
File f = fi.getStoreLocation();
FileInputStream in = new FileInputStream(f);//载入文档
//如果是office2007 docx格式
// if(filePath.toLowerCase().endsWith("docx")){
//word 2007 图片不会被读取, 表格中的数据会被放在字符串的最后
XWPFDocument xwpf = new XWPFDocument(in);//得到word文档的信息
// List<XWPFParagraph> listParagraphs = xwpf.getParagraphs();//得到段落信息
Iterator<XWPFTable> it = xwpf.getTablesIterator();//得到word中的表格
int s = 0;
while(it.hasNext()){
++s;
XWPFTable table = it.next();
List<XWPFTableRow> rows=table.getRows();
// 如果是第一页
if(s == 1){
//读取每一行数据
for (int i = 0; i < rows.size(); i++) {
XWPFTableRow row = rows.get(i);
//读取每一列数据
List<XWPFTableCell> cells = row.getTableCells();
// 第一页的第0行
if(i == 0){
List<Map<String,String>> list = this.ImplCell7_(cells);
li.add(list);
}else if(i == 1 || i == 2){
List<Map<String,String>> list = this.ImplCell7(cells);
li.add(list);
}else if(i == 3){
List<Map<String,String>> list = this.ImplCell4(cells);
li.add(list);
}else if(i == 4){
// 学历学位 最高学历学位
List<Map<String,String>> list = this.ImplCell6(cells);
li.add(list);
}else if(i == 5){
// 学历学位 工作学历学位
List<Map<String,String>> list = this.ImplCell6_(cells);
li.add(list);
}else if(i == 6 || i == 7 || i == 8){
// 职务信息
List<Map<String,String>> list = this.ImplCell2(cells);
li.add(list);
}else {
// 简历内容, 无法确定多少行, 在else中i
List<Map<String,String>> list = ImplCellResume2(cells);
if(list.size() > 0){
resumeList.add(list);
}
}
}
}else if(s == 2){
// 如果是第二页,进入这里
// 行 减一 , 不去解析最后一行, ==> 审批机关意见
for (int i = 0; i < rows.size(); i++) {
XWPFTableRow row = rows.get(i);
//读取每一列数据
List<XWPFTableCell> cells = row.getTableCells();
if(i == 0 || i == 1 || i == 2){
List<Map<String,String>> list = ImplCell2(cells);
li.add(list);
}else {
// 家庭信息 及 下面的行
for(int z = 0 ; z < cells.size() ; z++){
if(z == 0){
String str = cells.get(z).getText();
String st = StringUtil.replaceBlank(str);
if(StringUtil.equals(st,"呈报单位")){
List<Map<String,String>> list = ImplCell2_(cells);
li.add(list);
}else if(StringUtil.equals(st,"审批机关意见")){
continue;
}else if(StringUtil.equals(st,"主要家庭成员及社会关系")){
// 家庭信息的表头
lists2 = this.ImplCellList3(cells);
}else {
// 剩下的全是家庭信息
List<Map<String,String>> list = this.ImplCellList4(lists2,cells);
lists3.add(list);
}
}
}
}
}
}
}
}catch (Exception e){
e.printStackTrace();
}
return resumeList;
}
/**
* 返回家庭信息
* @param file
*/
public List<List<Map<String,String>>> wordWork2_1(MultipartFile file){
// 职员基本信息
List<List<Map<String,String>>> li = new LinkedList<>();
// 简历信息
List<List<Map<String,String>>> resumeList = new LinkedList<>();
// 家庭信息的表头
List<String> lists2 = new LinkedList<>();
// 家庭信息
List<List<Map<String,String>>> lists3 = new LinkedList<>();
try {
//===========================================================================================================
// 会在项目的根目录的临时文件夹下生成一个文件; 未解决 MultipartFile 转化为 File, 此方法有缺点
// //===========================================================================================================
CommonsMultipartFile cf= (CommonsMultipartFile)file;
DiskFileItem fi = (DiskFileItem)cf.getFileItem();
File f = fi.getStoreLocation();
FileInputStream in = new FileInputStream(f);//载入文档
//如果是office2007 docx格式
// if(filePath.toLowerCase().endsWith("docx")){
//word 2007 图片不会被读取, 表格中的数据会被放在字符串的最后
XWPFDocument xwpf = new XWPFDocument(in);//得到word文档的信息
// List<XWPFParagraph> listParagraphs = xwpf.getParagraphs();//得到段落信息
Iterator<XWPFTable> it = xwpf.getTablesIterator();//得到word中的表格
int s = 0;
while(it.hasNext()){
++s;
XWPFTable table = it.next();
List<XWPFTableRow> rows=table.getRows();
// 如果是第一页
if(s == 1){
//读取每一行数据
for (int i = 0; i < rows.size(); i++) {
XWPFTableRow row = rows.get(i);
//读取每一列数据
List<XWPFTableCell> cells = row.getTableCells();
// 第一页的第0行
if(i == 0){
List<Map<String,String>> list = this.ImplCell7_(cells);
li.add(list);
}else if(i == 1 || i == 2){
List<Map<String,String>> list = this.ImplCell7(cells);
li.add(list);
}else if(i == 3){
List<Map<String,String>> list = this.ImplCell4(cells);
li.add(list);
}else if(i == 4){
// 学历学位 最高学历学位
List<Map<String,String>> list = this.ImplCell6(cells);
li.add(list);
}else if(i == 5){
// 学历学位 工作学历学位
List<Map<String,String>> list = this.ImplCell6_(cells);
li.add(list);
}else if(i == 6 || i == 7 || i == 8){
// 职务信息
List<Map<String,String>> list = this.ImplCell2(cells);
li.add(list);
}else {
// 简历内容, 无法确定多少行, 在else中
List<Map<String,String>> list = ImplCellResume2(cells);
if(list.size() > 0){
resumeList.add(list);
}
}
}
}else if(s == 2){
// 如果是第二页,进入这里
// 行 减一 , 不去解析最后一行, ==> 审批机关意见
for (int i = 0; i < rows.size(); i++) {
XWPFTableRow row = rows.get(i);
//读取每一列数据
List<XWPFTableCell> cells = row.getTableCells();
if(i == 0 || i == 1 || i == 2){
List<Map<String,String>> list = ImplCell2(cells);
li.add(list);
}else {
// 家庭信息 及 下面的行
for(int z = 0 ; z < cells.size() ; z++){
if(z == 0){
String str = cells.get(z).getText();
String st = StringUtil.replaceBlank(str);
if(StringUtil.equals(st,"呈报单位")){
List<Map<String,String>> list = ImplCell2_(cells);
li.add(list);
}else if(StringUtil.equals(st,"审批机关意见")){
continue;
}else if(StringUtil.equals(st,"主要家庭成员及社会关系")){
// 家庭信息的表头
lists2 = this.ImplCellList3(cells);
}else {
// 剩下的全是家庭信息
List<Map<String,String>> list = this.ImplCellList4(lists2,cells);
lists3.add(list);
}
}
}
}
}
}
}
}catch (Exception e){
e.printStackTrace();
}
return lists3;
}
//==================================================================================================================================
// 公用方法, 读取行数据
//==================================================================================================================================
// 一行 2 列
private List<Map<String,String>> ImplCell2(List<XWPFTableCell> cells){
List<Map<String,String>> list = new LinkedList<>();
String key = "";
for (int j = 0; j < cells.size(); j++) {
Map<String,String> map = new HashMap<>();
XWPFTableCell cell=cells.get(j);
// value
if(j == 1){
if(StringUtil.isEmptys(cell.getText())){
map.put(key,StringUtil.replaceBlank(cell.getText()));
}else {
map.put(key,"空");
}
}
// key
if(j == 0){
if(StringUtil.isEmptys(cell.getText())){
key = StringUtil.replaceBlank(cell.getText());
}else {
key = "空";
}
}
//输出当前的单元格的数据
System.out.println( j + "列" + cell.getText());
for(Map.Entry<String,String> m : map.entrySet()){
if(StringUtil.isEmptys(m.getKey()) && StringUtil.isEmptys(m.getValue())){
list.add(map);
}
}
}
return list;
}
// 一行 2 列
private List<Map<String,String>> ImplCell2_(List<XWPFTableCell> cells){
List<Map<String,String>> list = new LinkedList<>();
String key = "";
for (int j = 0; j < cells.size(); j++) {
Map<String,String> map = new HashMap<>();
XWPFTableCell cell=cells.get(j);
// value
if(j == 1){
if(StringUtil.isEmptys(cell.getText())){
String value = StringUtil.replaceBlank(cell.getText());
map.put(key,value.substring(0,value.indexOf("(")));
}else {
map.put(key,"空");
}
}
// key
if(j == 0){
if(StringUtil.isEmptys(cell.getText())){
key = StringUtil.replaceBlank(cell.getText());
}else {
key = "空";
}
}
//输出当前的单元格的数据
System.out.println( j + "列" + cell.getText());
for(Map.Entry<String,String> m : map.entrySet()){
if(StringUtil.isEmptys(m.getKey()) && StringUtil.isEmptys(m.getValue())){
list.add(map);
}
}
}
return list;
}
// 一行 4 列
private List<Map<String,String>> ImplCell4(List<XWPFTableCell> cells){
List<Map<String,String>> list = new LinkedList<>();
String key = "";
for (int j = 0; j < cells.size(); j++) {
Map<String,String> map = new HashMap<>();
XWPFTableCell cell=cells.get(j);
// value
if(j == 1 || j == 3){
if(StringUtil.isEmptys(cell.getText())){
map.put(key,StringUtil.replaceBlank(cell.getText()));
}else {
map.put(key,"");
}
}
// key
if(j == 0 || j == 2){
if(StringUtil.isEmptys(cell.getText())){
key = StringUtil.replaceBlank(cell.getText());
}else {
key = "空";
}
}
//输出当前的单元格的数据
System.out.println( j + "列" + cell.getText());
for(Map.Entry<String,String> m : map.entrySet()){
if(StringUtil.isEmptys(m.getKey()) && StringUtil.isEmptys(m.getValue())){
list.add(map);
}
}
}
return list;
}
// 一行 5 列
private List<Map<String,String>> ImplCell5(List<XWPFTableCell> cells){
List<Map<String,String>> list = new LinkedList<>();
String key = "";
for (int j = 0; j < cells.size(); j++) {
Map<String,String> map = new HashMap<>();
XWPFTableCell cell=cells.get(j);
// value
if(j == 2 || j == 4){
if(StringUtil.isEmptys(cell.getText())){
map.put(key,StringUtil.replaceBlank(cell.getText()));
}else {
map.put(key,"");
}
}
// key
if(j == 1 || j == 3){
if(StringUtil.isEmptys(cell.getText())){
key = StringUtil.replaceBlank(cell.getText());
}else {
key = "空";
}
}
//输出当前的单元格的数据
System.out.println( j + "列" + cell.getText());
for(Map.Entry<String,String> m : map.entrySet()){
if(StringUtil.isEmptys(m.getKey()) && StringUtil.isEmptys(m.getValue())){
list.add(map);
}
}
}
return list;
}
// 一行 5 列 其中有/ , 一个单元格对应多个参数 最高学习经历
private List<Map<String,String>> ImplCell6(List<XWPFTableCell> cells){
List<Map<String,String>> list = new LinkedList<>();
String key = "";
String key2 = "最高";
String key3 = "最高";
for(int i = 0 ; i < cells.size() ;i++){
if(i == 0){
continue;
}else if(i == 1){
String str = cells.get(i).getText();
String st = StringUtil.replaceBlank(str);
key = st;
}else if(i == 2){
Map<String,String> map = new HashMap<>();
String str = cells.get(i).getText();
String st = StringUtil.replaceBlank(str);
if(StringUtil.isEmptys(st)){
map.put(key,st);
}else {
map.put(key,"空");
}
list.add(map);
}else if(i == 3){
String str = cells.get(i).getText();
String st = StringUtil.replaceBlank(str);
String[] strs = st.split("及");
for(int z =0 ; z < strs.length ; z++){
if(z == 0){
key2 += strs[z].toString();
}else if(z == 1){
key3 += strs[z].toString();
}
}
}else if(i == 4){
Map<String,String> map = new HashMap<>();
String str = cells.get(i).getText();
String st = StringUtil.replaceBlank(str);
String[] strs = st.split("/");
for(int z = 0 ; z < strs.length ; z++){
if(z == 0){
if(StringUtil.isEmptys(strs[z].toString())){
map.put(key2,strs[z].toString());
}else {
map.put(key2,"空");
}
}else if(z == 1){
if(StringUtil.isEmptys(strs[z].toString())){
map.put(key3,strs[z].toString());
}else {
map.put(key3,"空");
}
}
}
list.add(map);
}
}
return list;
}
// 一行 5 列 其中有/ , 一个单元格对应多个参数 工作学习经历
private List<Map<String,String>> ImplCell6_(List<XWPFTableCell> cells){
List<Map<String,String>> list = new LinkedList<>();
String key = "";
String key2 = "工作";
String key3 = "工作";
for(int i = 0 ; i < cells.size() ;i++){
if(i == 0){
continue;
}else if(i == 1){
String str = cells.get(i).getText();
String st = StringUtil.replaceBlank(str);
key = st;
}else if(i == 2){
Map<String,String> map = new HashMap<>();
String str = cells.get(i).getText();
String st = StringUtil.replaceBlank(str);
if(StringUtil.isEmptys(st)){
map.put(key,st);
}else {
map.put(key,"空");
}
list.add(map);
}else if(i == 3){
String str = cells.get(i).getText();
String st = StringUtil.replaceBlank(str);
String[] strs = st.split("及");
for(int z =0 ; z < strs.length ; z++){
if(z == 0){
key2 += strs[z].toString();
}else if(z == 1){
key3 += strs[z].toString();
}
}
}else if(i == 4){
Map<String,String> map = new HashMap<>();
String str = cells.get(i).getText();
String st = StringUtil.replaceBlank(str);
String[] strs = st.split("/");
for(int z = 0 ; z < strs.length ; z++){
if(z == 0){
if(StringUtil.isEmptys(strs[z].toString())){
map.put(key2,strs[z].toString());
}else {
map.put(key2,"空");
}
}else if(z == 1){
if(StringUtil.isEmptys(strs[z].toString())){
map.put(key3,strs[z].toString());
}else {
map.put(key3,"空");
}
}
}
list.add(map);
}
}
return list;
}
// 一行 7 列
private List<Map<String,String>> ImplCell7(List<XWPFTableCell> cells){
List<Map<String,String>> list = new LinkedList<>();
String key = "";
for (int j = 0; j < cells.size(); j++) {
Map<String,String> map = new HashMap<>();
XWPFTableCell cell=cells.get(j);
// value
if(j == 1 || j == 3 || j == 5){
if(StringUtil.isEmptys(cell.getText())){
map.put(key,StringUtil.replaceBlank(cell.getText()));
}else {
map.put(key,"空");
}
}
// key
if(j == 0 || j == 2 || j == 4){
if(StringUtil.isEmptys(cell.getText())){
key = StringUtil.replaceBlank(cell.getText());
}else {
key = "空";
}
}
for(Map.Entry<String,String> m : map.entrySet()){
if(StringUtil.isEmptys(m.getKey()) && StringUtil.isEmptys(m.getValue())){
list.add(map);
}
}
}
return list;
}
// 一行 7 列 带特殊字段 ==》 出生年月(岁)
private List<Map<String,String>> ImplCell7_(List<XWPFTableCell> cells){
List<Map<String,String>> list = new LinkedList<>();
String key = "";
String key2 = "";
String key3 = "";
for (int j = 0; j < cells.size(); j++) {
Map<String,String> map = new HashMap<>();
XWPFTableCell cell=cells.get(j);
// value
if(j == 1 || j == 3){
if(StringUtil.isEmptys(cell.getText())){
map.put(key,StringUtil.replaceBlank(cell.getText()));
}else {
map.put(key,"空");
}
}
// key
if(j == 0 || j == 2){
if(StringUtil.isEmptys(cell.getText())){
key = StringUtil.replaceBlank(cell.getText());
}else {
key = "空";
}
}
// 特殊处理key
if(j == 4){
if(StringUtil.isEmptys(cell.getText())){
// 截取年份
String str = cell.getText();
key2 = str.substring(0,str.indexOf("("));
// 截取年纪 ()
key3 = str.substring(str.indexOf("(")+1,str.indexOf(")"));
}
}
if(j == 5){
if(StringUtil.isEmptys(cell.getText())){
// 截取年份
String str = cell.getText();
String birthday = str.substring(0,str.indexOf("("));
map.put(key2,birthday);
// 年纪
String age = str.substring(str.indexOf("(")+1,str.indexOf("岁"));
map.put(key3,age);
}
}
for(Map.Entry<String,String> m : map.entrySet()){
if(StringUtil.isEmptys(m.getKey()) && StringUtil.isEmptys(m.getValue())){
list.add(map);
}
}
}
return list;
}
private List<String> ImplCellList(List<XWPFTableCell> cells){
// 列表表头
List<String> list1 = new LinkedList<>();
for(int i = 0 ; i < cells.size(); i++){
if(i == 0){
continue;
}else if(i == 1){
// list1.add(cells.get(i).getText()); // 起始时间
list1.add("开始时间");
list1.add("结束时间");
}else if(i == 2){
String str = cells.get(i).getText();
String[] strs = str.split("/");
for(int j = 0 ; j < strs.length ; j++){
list1.add(strs[j].toString());
}
}else if(i == 3){
String str = cells.get(i).getText();
String[] strs = str.split("/");
for(int j = 0 ; j < strs.length ; j++){
list1.add(strs[j].toString());
}
}
}
return list1;
}
private List<List<Map<String,String>>> ImplCellList2(List<String> implCellList,List<XWPFTableCell> cells){
List<List<Map<String,String>>> li = new LinkedList<>();
for(int i = 0 ; i < cells.size() ; i++){
if(i == 2){
String str = cells.get(i).getText();
System.out.println(str);
String[] strs = str.split(";");
for(int j = 0 ; j < strs.length ; j++){
List<Map<String,String>> list = new LinkedList<>();
String st = StringUtil.replaceBlank(strs[j]);
String[] sts = st.split(",");
for(int k = 0 ; k < sts.length ; k ++){
// 前半部分 , 起止时间
if(k == 0){
String ss = sts[k];
String[] sss = ss.split("-");
for(int l =0 ; l < sss.length ; l++){
// 表头key , 数据value
Map<String,String> map = new HashMap<>();
if(l == 0){
// 开始时间
map.put(implCellList.get(0),sss[l].toString());
}else if(l == 1){
// 结束时间
map.put(implCellList.get(1),sss[l].toString());
}
list.add(map);
}
}else if(k == 1){
String ss = sts[k];
String[] sss = ss.split("/");
for(int l = 0; l < sss.length ; l++){
// 表头key , 数据value
Map<String,String> map = new HashMap<>();
if(l == 0){
// 单位
if(StringUtil.isEmptys(sss[l].toString())){
map.put(implCellList.get(2),sss[l].toString());
}
}else if(l == 1){
if(StringUtil.isEmptys(sss[l].toString())){
map.put(implCellList.get(3),sss[l].toString());
}
}else if(l == 2){
if(StringUtil.isEmptys(sss[l].toString())){
map.put(implCellList.get(4),sss[l].toString());
}
}else if(l == 3){
if(StringUtil.isEmptys(sss[l].toString())){
map.put(implCellList.get(5),sss[l].toString());
}
}
list.add(map);
}
}
}
li.add(list);
}
}
}
return li;
}
private List<String> ImplCellList3(List<XWPFTableCell> cells){
List<String> list = new LinkedList<>();
for(int i = 0 ; i < cells.size() ; i++){
if(i == 0){
continue;
}
String str = cells.get(i).getText();
String st = StringUtil.replaceBlank(str);
list.add(st);
}
return list;
}
private List<Map<String,String>> ImplCellList4(List<String> lists,List<XWPFTableCell> cells){
List<Map<String,String>> list = new LinkedList<>();
for( int i = 0 ; i < cells.size() ; i++){
if(i == 0){
continue;
}else if(i == 1){
Map<String,String> map = new HashMap<>();
String str = cells.get(i).getText();
if(StringUtil.isEmptys(str)){
String st = StringUtil.replaceBlank(str);
map.put(lists.get(0).toString(),st);
list.add(map);
}else {
break;
}
}else if(i == 2){
Map<String,String> map = new HashMap<>();
String str = cells.get(i).getText();
if(StringUtil.isEmptys(str)){
String st = StringUtil.replaceBlank(str);
map.put(lists.get(1).toString(),st);
list.add(map);
}else {
map.put(lists.get(1).toString(),"空");
list.add(map);
}
}else if(i == 3){
Map<String,String> map = new HashMap<>();
String str = cells.get(i).getText();
if(StringUtil.isEmptys(str)){
String st = StringUtil.replaceBlank(str);
map.put(lists.get(2).toString(),st);
list.add(map);
}else {
map.put(lists.get(2).toString(),"空");
list.add(map);
}
}else if(i == 4){
Map<String,String> map = new HashMap<>();
String str = cells.get(i).getText();
if(StringUtil.isEmptys(str)){
String st = StringUtil.replaceBlank(str);
map.put(lists.get(3).toString(),st);
list.add(map);
}else {
map.put(lists.get(3).toString(),"空");
list.add(map);
}
}else if(i == 5){
Map<String,String> map = new HashMap<>();
String str = cells.get(i).getText();
if(StringUtil.isEmptys(str)){
String st = StringUtil.replaceBlank(str);
map.put(lists.get(4).toString(),st);
list.add(map);
}else {
map.put(lists.get(4).toString(),"空");
list.add(map);
}
}
}
return list;
}
// 解析简历 步骤 : 1 , 查看第 1 列是否有值
private boolean ImplCellResume1(List<XWPFTableCell> cells){
boolean bo = false; // 默认有值
for(int i = 0 ; i < cells.size(); i++){
// 跳出第一次循环,
if(i == 0){
continue;
}else if(i == 1){
String cell = StringUtil.replaceBlank(cells.get(i).getText());
if(StringUtil.isEmpty(cell)){
bo = true; // 没有值
}
}
}
return bo;
}
// 解析 简历字段中的时间
private Map<String,String> ImplCellResumeTime(String time){
Map<String,String> map = new HashMap<>();
String[] strs = time.split("-");
for(int i = 0 ; i < strs.length ; i++){
if(i == 0){
// 开始时间
String statTime = StringUtil.replaceBlank(strs[i].toString());
if(StringUtil.isEmptys(statTime)){
map.put("开始时间",strs[i].toString());
}else {
map.put("开始时间","空");
}
}else if(i == 1){
String endTime = StringUtil.replaceBlank(strs[i].toString());
// 结束时间
if(StringUtil.isEmptys(endTime)){
map.put("结束时间",strs[i].toString());
}else {
// 如果截取到的结束时间为空 , 则默认为 至今
map.put("结束时间","至今");
}
}
}
return map;
}
// 解析单位
private Map<String,String> ImplCellResumeDept(String dept){
Map<String,String> map = new HashMap<>();
// 不为空
if(StringUtil.isEmptys(dept)){
map.put("单位",dept);
}else {
// 为空
map.put("单位","空");
}
return map;
}
private List<Map<String,String>> ImplCellResume2(List<XWPFTableCell> cells){
List<Map<String,String>> list = new LinkedList<>();
// 判断次行数据第一列是否为空或者 空字符
boolean bo = this.ImplCellResume1(cells);
// 如果有值, 此数据完整, 不用拼接在上一行后面
if(bo == false){
for(int i = 0 ; i < cells.size(); i++){
Map<String,String> map = new HashMap<>();
if(i == 0){
continue;
}else if(i == 1){
// 开始时间 , 结束时间
if(StringUtil.isEmptys(cells.get(i).getText())){
Map<String,String> m = this.ImplCellResumeTime(cells.get(i).getText());
for(Map.Entry<String,String> mm : m.entrySet()){
if(!mm.getValue().equals("空") || StringUtil.isEmptys(mm.getValue())){
map.put(mm.getKey(),mm.getValue());
}
}
}
}else if(i == 2){
if(StringUtil.isEmptys(cells.get(i).getText())){
// 单位
Map<String,String> m = this.ImplCellResumeDept(cells.get(i).getText());
for(Map.Entry<String,String> mm : m.entrySet()){
if(!mm.getValue().equals("空") || StringUtil.isEmptys(mm.getValue())){
map.put(mm.getKey(),mm.getValue());
}
}
}
}
list.add(map);
}
}else {
// 如果没有值, 此数据不是完整的
for(int i =0 ; i < cells.size(); i++){
// 上面判断了第一列为null, 所以这里直接存储
if(i == 0 || i == 1){
// 第0 为标题 , 跳过, 第 1 为时间 , 上面判断了 , 时间为null 才会到下面来 , 所以跳过
continue;
}else if(i == 2){
Map<String,String> map = new HashMap<>();
String de = StringUtil.replaceBlank(cells.get(i).getText());
if(StringUtil.isEmptys(de)){
map.put("单位",de);
list.add(map);
}
}
}
}
return list;
}
}
word 导入
发布于 2019-06-26 715 次阅读
叨叨几句... NOTHING