读取Word 内容

import org.apache.poi.POIXMLDocument;
import org.apache.poi.POIXMLTextExtractor;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 *  Word 读取Word 内容, 但是没有格式, 图片读取不了
 */
public class ImortWordUtil {

    public static void main(String[] args){
        StringBuffer str = readWord("C:/Users/Lenovo/Desktop/test/xxxxx.docx");
        System.out.println(str.toString());
    }

    public static StringBuffer readWord(String path) {
        String s = "";
        try {
            if(path.endsWith(".doc")) {
                InputStream is = new FileInputStream(new File(path));
                WordExtractor ex = new WordExtractor(is);
                s = ex.getText();
            }else if (path.endsWith("docx")) {
                OPCPackage opcPackage = POIXMLDocument.openPackage(path);
                POIXMLTextExtractor extractor = new XWPFWordExtractor(opcPackage);
                s = extractor.getText();
            }else {
                System.out.println("传入的word文件不正确:"+path);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        StringBuffer bf = new StringBuffer(s);
        return bf;
    }
}//=================================================================================================================


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\\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;
    }

 

//==================================================================================================================================
//       公用方法, 读取行数据
//==================================================================================================================================

    // 一行 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;
    }


}

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

饭酱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值