C# with Excel

Mar 27 2012 2:50 AM
Dear All,
Season greetings,

1. I need to select a Excel cell by user click on run time,

2. while opening an existing excel file to write some data and at the end we need to save and close, here is also some errors,

PLease any one can help?

Here is my code,


{

Excel.

Excel.

Excel.


private void button1_Click(object sender, EventArgs e)Application xlApp;Workbook xlWorkBook;Worksheet xlWorkSheet;///Excel.Range range;



xlApp =

xlWorkBook = xlApp.Workbooks.Open(filename, 0,

xlWorkSheet = (Excel.

Excel.

myCell.Value2 =


object misValue = System.Reflection.Missing.Value;string filename = "C:\\S1.xls";new Excel.Application();true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);Worksheet)xlWorkBook.Worksheets.get_Item(1); Range myCell = (Excel.Range)xlWorkSheet.get_Range("E4", "E4");"This is Excel Interface";///xlWorkBook.SaveAs(filename, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);


xlWorkBook.Close(

xlApp.Quit();

releaseObject(xlWorkSheet);

releaseObject(xlWorkBook);

releaseObject(xlApp);


}


{


true, misValue, misValue);MessageBox.Show("Test OK");private void releaseObject(object obj)try

{

System.Runtime.InteropServices.

obj =

}


{

obj =


}


Marshal.ReleaseComObject(obj);null;catch (Exception ex)null;MessageBox.Show("Unable to release the Object " + ex.ToString());finally

{


}

}

GC.Collect();

}
}

regards,
Jawahar

Answers (3)