package com.icourt.util;import org.apache.commons.collections4.CollectionUtils;import org.apache.poi.openxml4j.exceptions.InvalidFormatException;import org.apache.poi.ss.usermodel.*;import org.apache.poi.ss.util.CellRangeAddress;import java.io.*;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Map.Entry;import java.util.regex.Matcher;import java.util.regex.Pattern;/**
* 描述:poi根据模板导出excel,根据excel坐标赋值,如(B1) */public class ExcelExportUtil {//模板mapprivate Map tempWorkbook = new HashMap();//模板输入流mapprivate Map tempStream = new HashMap();/** * 功能:按模板向Excel中相应地方填充数据 */public void writeData(String templateFilePath, Map dataMap, int sheetNo) throws IOException, InvalidFormatException {if (dataMap == null || dataMap.isEmpty()) {return;
}//读取模板Workbook wbModule = getTempWorkbook(templateFilePath);//数据填充的sheetSheet wsheet = wbModule.getSheetAt(sheetNo);for (Entry entry : dataMap.entrySet()) {
String point = entry.getKey();
Object data = entry.getValue();
TempCell cell = getCell(point, data, wsheet);//指定坐标赋值 setCell(cell, wsheet);
}//设置生成excel中公式自动计算wsheet.setForceFormulaRecalculation(true);
}/** * 功能:按模板向Excel中列表填充数据.只支持列合并 */public void writeDateList(String templateFilePath, String[] heads, List