This question already has an answer here:
这个问题在这里已有答案:
- Excel add data to WorksheetPart in code behind 1 answer
- Excel在1个答案后面的代码中向WorksheetPart添加数据
- Excel insert rows (not Add) 3 answers
- Excel插入行(不是添加)3个答案
I need to insert a new row below the first row. using the code below, what i need to add to make it done ?
我需要在第一行下面插入一个新行。使用下面的代码,我需要添加什么来完成它?
Excel.Application excelApp = new Excel.Application();
string myPath = @"Data.xlsx";
excelApp.Workbooks.Open(myPath);
// Get Worksheet
Excel.Worksheet worksheet = excelApp.Worksheets[1];
int rowIndex = 2; int colIndex = 2;
for (int i = 0; i < 10; i++)
{
excelApp.Cells[rowIndex, colIndex] = "\r123";
}
excelApp.Visible = false;
Thanks :)
谢谢 :)
1 个解决方案
#1
12
Suppose you want to add in the third line:
假设您要添加第三行:
Range line = (Range)worksheet.Rows[3];
line.Insert();
#1
12
Suppose you want to add in the third line:
假设您要添加第三行:
Range line = (Range)worksheet.Rows[3];
line.Insert();