NET npoi 合并单元值处理
获取sheet中存在合并单元格总数,循环绑定值
// 得到一个sheet中有多少个合并单元格 int sheetMergeCount = sheet.NumMergedRegions; for (var i = 0; i < sheetMergeCount; i++) { // 获取合并后的单元格 var range = sheet.GetMergedRegion(i); sheet.IsMergedRegion(range); var cellValue = sheet.GetRow(range.FirstRow).GetValue(range.FirstColumn).FormatUtf8String(); for (var mRowIndex = range.FirstRow; mRowIndex <= range.LastRow; mRowIndex++) { for (var mColumnIndex = range.FirstColumn; mColumnIndex <= range.LastColumn; mColumnIndex++) { table.Rows[mRowIndex][mColumnIndex] = cellValue; } } }
完整帮助类代码:ASPNET npoi帮助类