npoi4.0 在excel中插入行,后续行被覆盖掉,请帮忙解决

nikolaichow 2017-04-16 01:17:39
我使用npoi4.0 想插入几行记录到指定的位置,插入行后的记录后移,不能覆盖,现在使用代码覆盖掉,请帮忙解决解决。




int kRow=10;

ICellStyle cellStyle = sheet.GetRow(kRow).GetCell(kCol).CellStyle;
short rowHight = sheet.GetRow(kRow).Height;
int kLastRowIndex = sheet.LastRowNum;
for (int i = kRow; i < kRow+ table.data.Rows.Count - 1; i++)
{
IRow row = sheet.CreateRow(i+1);
NPOI.SS.UserModel.ICell cell = row.CreateCell(0);
cell.CellStyle = cellStyle;
cell.SetCellValue("ttt");
}


...全文
909 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
纸纸纸纸飞飞 2018-01-09
  • 打赏
  • 举报
回复
引用 5 楼 bing_zz 的回复:
[quote=引用 4 楼 vlevle 的回复:] [quote=引用 2 楼 nikolaichow的回复:][quote=引用 1 楼 vlevle 的回复:] sheet.ShiftRows(int startRow, int endRow, int n); sheet.ShiftRows(int startRow, int endRow, int n, bool copyRowHeight, bool resetOriginalRowHeight);
这个是移动行,会覆盖掉原有的记录。还有其他的吗?或者其他示例[/quote] 你要在第5行插入2行,不应该先把从第5行开始到最后的所有行往下移动2行吗?[/quote] 你上用哪个版本的NPOI,我用NuGet里下载的,试了2.3、2.1,2.0,都在ShiftRows报错: 1、2.3 报Name'get.workboo' is completely unknown in the current workbook 2、2.1报not implemented yet 3、2.0报空值异常[/quote] 报错,说明用法上有问题。 我在代码中有使用,没有问题的。
韮菜饼 2017-09-01
  • 打赏
  • 举报
回复
引用 4 楼 vlevle 的回复:
[quote=引用 2 楼 nikolaichow的回复:][quote=引用 1 楼 vlevle 的回复:] sheet.ShiftRows(int startRow, int endRow, int n); sheet.ShiftRows(int startRow, int endRow, int n, bool copyRowHeight, bool resetOriginalRowHeight);
这个是移动行,会覆盖掉原有的记录。还有其他的吗?或者其他示例[/quote] 你要在第5行插入2行,不应该先把从第5行开始到最后的所有行往下移动2行吗?[/quote] 你上用哪个版本的NPOI,我用NuGet里下载的,试了2.3、2.1,2.0,都在ShiftRows报错: 1、2.3 报Name'get.workboo' is completely unknown in the current workbook 2、2.1报not implemented yet 3、2.0报空值异常
vlevle 2017-04-22
  • 打赏
  • 举报
回复
引用 2 楼 nikolaichow的回复:
[quote=引用 1 楼 vlevle 的回复:] sheet.ShiftRows(int startRow, int endRow, int n); sheet.ShiftRows(int startRow, int endRow, int n, bool copyRowHeight, bool resetOriginalRowHeight);
这个是移动行,会覆盖掉原有的记录。还有其他的吗?或者其他示例[/quote] 你要在第5行插入2行,不应该先把从第5行开始到最后的所有行往下移动2行吗?
xuzuning 2017-04-17
  • 打赏
  • 举报
回复
nikolaichow 2017-04-17
  • 打赏
  • 举报
回复
引用 1 楼 vlevle 的回复:
sheet.ShiftRows(int startRow, int endRow, int n); sheet.ShiftRows(int startRow, int endRow, int n, bool copyRowHeight, bool resetOriginalRowHeight);
这个是移动行,会覆盖掉原有的记录。还有其他的吗?或者其他示例
vlevle 2017-04-16
  • 打赏
  • 举报
回复
sheet.ShiftRows(int startRow, int endRow, int n); sheet.ShiftRows(int startRow, int endRow, int n, bool copyRowHeight, bool resetOriginalRowHeight);

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧