EPPlus 合并单元格
/// <summary> /// 合并单元格 /// </summary> /// <param name="sheet"></param> /// <param name="col">要合并的列索引</param> private void MergeCell(ExcelWorksheet sheet, int col) { int fromRow = ROWSTARTINDEX + 1; int fromCol = col; int toRow = ROWSTARTINDEX + 1; int toCol = col; string v = sheet.Cells[ROWSTARTINDEX + 1, col].Value.ToString(); for (int i = ROWSTARTINDEX + 1; i < sheet.Cells.Rows; i++) { var vNext = sheet.Cells[i + 1, col].Value?.ToString(); if (v != vNext) { v = vNext; toRow = i; sheet.Cells[fromRow, fromCol, toRow, toCol].Merge = true; sheet.Cells[fromRow, fromCol, toRow, toCol].Style.VerticalAlignment = ExcelVerticalAlignment.Center; fromRow = i + 1; } if (vNext == null) { break; } } }
Newd
版权声明
作者:も不秃不秃
地址:https://www.cnblogs.com/Newd/p/12936790.html
© Newd 尊重知识产权,引用请注出处
广告位
(虚位以待,如有需要请私信)