easypoi merge cells horizontally and vertically

horizontal merger

Workbook workbook =sheetUtils.exportExcel(dto);
CellRangeAddress craOne = new CellRangeAddress(0, 1, 0, 1);
//CellRangeAddress(第几行开始,第几行结束,第几列开始,第几列结束)
workbook.getSheetAt(0).addMergedRegion(craOne);

vertical merger

PoiMergeCellUtil.mergeCells(workbook.getSheetAt(0), 6, 7);
//sheet页,开始行,需要合并的列数组
//相同内容的列自动合并

The same column is automatically merged

先生成work文件,代码省略


方式比较多,例如其中一种方式:
//生成列标题
List<ExcelExportEntity> tableHeaders = ...
//excel基本信息
ExportParams params = new ExportParams(ull,"excel名称",ExcelTpe.HSSF);
//生成excel文件
Workbook workbook = ExcelExportUtil.exportExcel(params,tableHeaders,tableDatas);

//进行excel前七列,相同的列数据,自动合并,从第一行开始
int[] relationColl = new int[]{0,1,2,3,4,5,6};
Map<Integer,int[]> mergeMap = new HashMap<>();
mergeMap.put(0,relationColl);
mergeMap.put(1,relationColl);
mergeMap.put(2,relationColl);
mergeMap.put(3,relationColl);
mergeMap.put(4,relationColl);
mergeMap.put(5,relationColl);
mergeMap.put(6,relationColl);
PoiMergeCellUtil.mergeCells(workbook.getSheetAt(0),mergeMap,1);


...response设置头信息进行下载导出

//The loop method can also be used here, and some rows are calculated in advance to be merged, and the logic is calculated, and the loop is used, and some rows and columns are merged when the data is the same

 

Guess you like

Origin blog.csdn.net/qq_44691484/article/details/129918543