2013-04-30 16 views
6

Devo inserire una nuova riga sotto la prima riga. usando il codice qui sotto, cosa devo aggiungere per farlo?Come aggiungere una nuova riga al file excel in C#

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

Questa domanda è stato chiesto già alcune volte, come ad esempio: http://stackoverflow.com/ domande/13418776/excel-insert-rows-not-add –

risposta

11

Supponiamo che si desidera aggiungere nella terza riga:

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

Incredibile, hai salvato la mia giornata :) –

Problemi correlati