标签:oid ksh i++ bubuko nbsp http OWIN nta src
导出的Excel数据,合并指令行并水平垂直居中
原始数据
合并后的数据
代码如下
/// <summary> /// 合并行 /// </summary> /// <param name="sheet"></param> /// <param name="startRowIndex"></param> /// <param name="mergeRowIndexs">合并行的行数,起始位置,终止位置</param> public static void MergeRowCells(ExcelWorksheet sheet, int startRowIndex, int[,] mergeRowIndexs) { for (int i = 0; i < mergeRowIndexs.Rank; i++) { sheet.Cells[mergeRowIndexs[i, 0] + startRowIndex, mergeRowIndexs[i, 1], mergeRowIndexs[i, 0] + startRowIndex, mergeRowIndexs[i, 2]].Merge = true; sheet.Cells[mergeRowIndexs[i, 0] + startRowIndex, mergeRowIndexs[i, 1], mergeRowIndexs[i, 0] + startRowIndex, mergeRowIndexs[i, 2]].Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; sheet.Cells[mergeRowIndexs[i, 0] + startRowIndex, mergeRowIndexs[i, 1], mergeRowIndexs[i, 0] + startRowIndex, mergeRowIndexs[i, 2]].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; } }
//行 int[,] mergeRowIndexs= { { 6, 2, 3 }, { 7, 2, 3 } }; EpplusHelper.MergeRowCells(worksheet, 2,mergeRowIndexs); package.Save();
标签:oid ksh i++ bubuko nbsp http OWIN nta src
原文地址:https://www.cnblogs.com/jishugaochao/p/10346255.html