Monday, July 27, 2009

How do i select the correct worksheet of an Excel file using C#?

i am using Microsoft.Office.Interop.Excel and so i cant get it to select the correct worksheet i want to work with within my excel work book. SO far I have:


Excel.Application excelApp = new Excel.Application();


excelApp.Workbooks.Open(@"C:\DotNet\Exce... false, false, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", true, false, null, false, null, false);


// select correct worksheet





int rowIndex = 30; int colIndex = 1;





excelApp.Cells[rowIndex, colIndex] = "SOme Text";


excelApp.Visible = true;





anyone have any ideas on how to write to the worksheet i want?

How do i select the correct worksheet of an Excel file using C#?
You're using properties associated with "excelApp", which is an Excel.Application object. But what you really need is an Excel.Worksheet object for that sheet you've selected. You can drill down to this using the ActiveSheet property of Microsoft.Office.Interop.Excel.Workbook.


No comments:

Post a Comment