var sheet = iWorkbook.GetSheet(sheetname);
// targetNum 插入序号,从1开始
switch (Direction)
{
case NPOIExcelTools.Direction.目标右侧:
targetNum += 1;
break;
case NPOIExcelTools.Direction.目标左侧:
break;
}
for (int r = 0; r < sheet.LastRowNum + 1; r++)
{
IRow row = sheet.GetRow(0);
short lastCellNum = row.LastCellNum;
row = sheet.GetRow(r);
for (int i = lastCellNum - 1; i >= targetNum; i--)
{
if (targetNum> lastCellNum)
{
continue; //越界
}
var cell = row.GetCell(i);
if (cell != null)
{
var newCell = row.CreateCell(i + insertCount);
row.CopyCell(i, i + insertCount);
cell.SetCellValue("");
}
}
}
NPOI 插入空列
最新推荐文章于 2024-12-31 10:54:52 发布