需要用到的类:CellRangeAddress
CellRangeAddress类的构造方法
public CellRangeAddress(int firstRow, int lastRow, int firstCol, int lastCol);
一共四个参数,分别是:待合并的开始行、结束行、开始列、结束列,参数均为索引值,从0开始。
headerRow.CreateCell(0).SetCellValue("姓名");
headerRow.GetCell(0).CellStyle = headStyle;
sheet.AddMergedRegion(new CellRangeAddress(1, 1, 0, 1)); //合并
headerRow.CreateCell(2).SetCellValue("年龄");
headerRow.GetCell(2).CellStyle = headStyle;
sheet.AddMergedRegion(new CellRangeAddress(1, 1, 2, 3)); //合并