easypoi的不定表头数据读取

package com.cyb.app.doc;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
public class EasyPoiUtils {

class 	EmpSaturation{
  private String deparement;
  private String empName;
  private String day;//哪一天 20221021
  private String post;//岗位
  private String hours;//工时
  private Double saturation;//当日饱和度 假定工时为7小时
  private String updEmp;//更新人员
  private String updTime;//更新时间
}
public static void main(String[] args) {
	List> list = new ArrayList>();
	Map headMap = new HashMap();
	GzdrListener gzdrListener = new GzdrListener(list,headMap);//作为构造参数,返回值为空!
	EasyExcel.read("D:\\001-2022-工作内容\\9998文件\\doc\\饱和度数据.xls", gzdrListener)
	.sheet("Sheet1")
	.doReadSync();
	System.out.println("main:"+list.size());
	System.out.println(headMap);
}
}
class GzdrListener extends AnalysisEventListener>{
	//用list集合保存解析到的结果
    private List> list=null;
	private Map headMap =null ;
	GzdrListener(List> list,Map headMap){
		this.list = list;
		this.headMap = headMap;
	}
	
	@Override
    public void invokeHeadMap(Map headMap, AnalysisContext context) {
		this.headMap = headMap;
		this.headMap.putAll(headMap);
		//logger.info("解析到一条头数据:{}, currentRowHolder: {}", headMap.toString(), context.readRowHolder().getRowIndex());
    }
	
	@Override
	public void invoke(Map row, AnalysisContext context) {
		// logger.info("解析到一条数据:{}, currentRowIndex: {}----", row.toString(), context.readRowHolder().getRowIndex());
		 list.add(row);
	}
	//数据库:部门名称、岗位名称、姓名、日期、工时、每日工时、更新时间、更新人员
	//报表 上个月、上一周、下一周、下个月

	@Override
	public void doAfterAllAnalysed(AnalysisContext context) {
		System.out.println("doAfterAllAnalysed:list:"+list.size());
		System.out.println("doAfterAllAnalysed:headMap:"+headMap);
		for(Map cur:list) {
			for(Integer col:cur.keySet()) {
				System.out.println(col+"="+cur.get(col));
				System.out.println(headMap.get(col)+"="+cur.get(col));
			}
		}
	}
	
}

你可能感兴趣的:(开发工具,excel,java,开发语言)