gpt4 book ai didi

NPOI像excel一样插入行

转载 作者:行者123 更新时间:2023-12-01 11:05:08 35 4
gpt4 key购买 nike

如何使用NPOI像excel一样插入一行?
excel插入命令复制上一行的格式

谢谢!

最佳答案

static void InsertRows(ref HSSFSheet sheet1, int fromRowIndex, int rowCount)
{
sheet1.ShiftRows(fromRowIndex, sheet1.LastRowNum, rowCount, true, false, true);

for (int rowIndex = fromRowIndex; rowIndex < fromRowIndex + rowCount; rowIndex++)
{
HSSFRow rowSource = sheet1.GetRow(rowIndex + rowCount);
HSSFRow rowInsert = sheet1.CreateRow(rowIndex);
rowInsert.Height = rowSource.Height;
for (int colIndex = 0; colIndex < rowSource.LastCellNum; colIndex++)
{
HSSFCell cellSource = rowSource.GetCell(colIndex);
HSSFCell cellInsert = rowInsert.CreateCell(colIndex);
if (cellSource != null)
{
cellInsert.CellStyle = cellSource.CellStyle;
}
}
}
}

也许你可以看看 here一些灵感

关于NPOI像excel一样插入行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6673623/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com