💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
**1. 继承拦截器AbstractMergeStrategy** ```java public class CustomMergeStrategy extends AbstractMergeStrategy { /** * 每个单元格都调用一次 */ @Override public void merge(Sheet sheet, Cell cell, Head head, Integer rowIndex) { if(rowIndex == 1 && cell.getColumnIndex() == 2) { //合并前2行,前3列 CellRangeAddress item = new CellRangeAddress(0, 1, 0, 2); sheet.addMergedRegion(item); } } } ``` **2. 注册拦截器** ```java @Test public void write02() { Integer num = 0; List<List<Integer>> dataList = Lists.newArrayList(); for (int row = 1; row <= 100; row++) { List<Integer> rowData = Lists.newArrayList(); for (int col = 1; col <= 50; col++) { rowData.add(num++); } dataList.add(rowData); } EasyExcel.write("e:/upload/easyexcel/007.xlsx") .sheet("Sheet1") //注册拦截器 .registerWriteHandler(new CustomMergeStrategy()) .doWrite(dataList); } ```