NPOI 合并单元格

来源:互联网 发布:数据统计报告范文 编辑:程序博客网 时间:2024/05/15 06:32

需要用到的类: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)); //合并

这里写图片描述

0 0
原创粉丝点击