How to add new row to excel file in C#

c#, excel

Solution

Suppose you want to add in the third line:

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

Problem

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 :)

Original source

Related problems