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
Veera ChennaPosted Mar 27, 2012, 11:14 PM
a) opening/saving an excel file
b) getting cell ranges & values
c) releasing memory resources
Jawahar RaghuramanPosted Mar 27, 2012, 4:51 AM
Thanks for your quick response,
1. when we run C# windows forms on that button click I need to select a Excel cell by user click on run time,
from this sample,
Excel.
instead of giving Range ("E4", "E4") let user should click by his own.
how to pause for user click on runtime, from C# to excel?
Once he clicks we need to get the cell value for further calculations on C#.
Could you please help me.
2. when I open an excel file thro. C# its working fine, but when I need to save & close,
the error i got is file already existing need to over write or not??
sample code,
xlWorkBook = xlApp.Workbooks.Open(filename, 0,
xlWorkBook.Close(
xlApp.Quit();
best regards,
Jawahar.
true, misValue, misValue);true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);Range myCell = (Excel.Range)xlWorkSheet.get_Range("E4", "E4");Sam HobbsPosted Mar 27, 2012, 4:11 AM