J
Jörgen Ahrens
Hi All
I have a probelm with Excel Automation. I create an Excel Application and
open a workbook. Then I close the workbook and Quit the Excel Application,
but the Excel.exe Process does not disapear...
What am i doing wrong?
Thanks
j.ahrens
My Code:
using System;
using System.Reflection;
using Excel = Microsoft.Office.Interop.Excel;
namespace TestApplication
{
/// <summary>
/// Summary description for ExcelTest.
/// </summary>
public class ExcelTest
{
[STAThread]
static void Main()
{
//my excel file
string file = @"C:\Tmp\Test.xls";
//Set culture to english-US, otherwise the interop won't work
System.Threading.Thread.CurrentThread.CurrentCulture = new
System.Globalization.CultureInfo("en-US");
//Create the excel application
Excel.ApplicationClass app = new
Microsoft.Office.Interop.Excel.ApplicationClass();
//Open the workbook
Excel.Workbook wb = app.Workbooks.Open(file, false, true, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value);
//Close the workbook
wb.Close(false, Missing.Value, Missing.Value);
//Release the workbook com reference
System.Runtime.InteropServices.Marshal.ReleaseComObject(wb);
wb = null;
//Close the excel application
app.Quit();
//Release the application com reference
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
app = null;
System.Threading.Thread.Sleep(5000);
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
}
I have a probelm with Excel Automation. I create an Excel Application and
open a workbook. Then I close the workbook and Quit the Excel Application,
but the Excel.exe Process does not disapear...
What am i doing wrong?
Thanks
j.ahrens
My Code:
using System;
using System.Reflection;
using Excel = Microsoft.Office.Interop.Excel;
namespace TestApplication
{
/// <summary>
/// Summary description for ExcelTest.
/// </summary>
public class ExcelTest
{
[STAThread]
static void Main()
{
//my excel file
string file = @"C:\Tmp\Test.xls";
//Set culture to english-US, otherwise the interop won't work
System.Threading.Thread.CurrentThread.CurrentCulture = new
System.Globalization.CultureInfo("en-US");
//Create the excel application
Excel.ApplicationClass app = new
Microsoft.Office.Interop.Excel.ApplicationClass();
//Open the workbook
Excel.Workbook wb = app.Workbooks.Open(file, false, true, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value);
//Close the workbook
wb.Close(false, Missing.Value, Missing.Value);
//Release the workbook com reference
System.Runtime.InteropServices.Marshal.ReleaseComObject(wb);
wb = null;
//Close the excel application
app.Quit();
//Release the application com reference
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
app = null;
System.Threading.Thread.Sleep(5000);
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
}