【问题标题】:How to add new row to excel file in C# [duplicate]如何在C#中向excel文件添加新行[重复]
【发布时间】:2017-02-07 17:35:36
【问题描述】:

我需要在第一行下方插入一个新行。 使用下面的代码,我需要添加什么来完成它?

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;

谢谢:)

【问题讨论】:

标签: c# excel


【解决方案1】:

假设要在第三行添加:

Range line = (Range)worksheet.Rows[3];
line.Insert();

【讨论】:

  • 太棒了,你拯救了我的一天 :)
猜你喜欢
  • 1970-01-01
  • 2020-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-19
  • 2018-07-24
  • 2020-08-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多