ICellStyle MergeCellstyle = workbook.CreateCellStyle();
MergeCellstyle.VerticalAlignment = VerticalAlignment.Center;
MergeCellstyle.Alignment = HorizontalAlignment.Center;
MergeCellstyle.BorderBottom = BorderStyle.Thin;
MergeCellstyle.BorderLeft = BorderStyle.Thin;
MergeCellstyle.BorderRight = BorderStyle.Thin;
MergeCellstyle.BorderTop = BorderStyle.Thin;
int iFromLine = 2;
int iToLine = 0;
int iCnt = 0;
{
int.TryParse(dtResult.Rows[i]["cntPlat"].ToString(), out iCnt);
if (iCnt != 0)
{
iToLine = iCnt + iFromLine - 1;
//sheet = mergeCell(sheet, iFromLine, iToLine, 0, 0);
sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(iFromLine, iToLine, 0, 0));
//设置合并后style
var cell = sheet.GetRow(iFromLine).GetCell(0);
cell.CellStyle = MergeCellstyle;
iFromLine += iCnt;
}
}