First of all, please read this:
How to automate Microsoft Excel from Microsoft Visual C#.NET[
^]
You have to use
Namespace alias[
^] as a shorthand of name to avoid repeating entire namespace. See:
Excel = Microsoft.Office.Interop.Excel;
Do not forget to clean up. It means, you have to relase all com objects you created in code! Take a look at below example:
Excel.Application xlApp = new Excel.Application();
string sFileName = @"D:\ConflictData.xls";
Excel.Workbook xlBook = (Excel.Workbook)xlApp.Workbooks.Open(sFileName);
Excel.Worksheet xlSheet = (Excel.Worksheet)xlBook.Worksheets[2];
for(int i =1; i<=10; i++)
{
xlSheet.Range["A" + i.ToString()].Value = i;
}
xlApp.Visible = true;
GC.Collect();
GC.WaitForPendingFinalizers();
Marshal.ReleaseComObject(xlSheet);
Marshal.ReleaseComObject(xlBook);
Marshal.ReleaseComObject(xlApp);