D
DAXU
Hello,
I did following code to open an excel sheet and now just close it. But
the problem is that the excel process created in my code is still
there when I use:
excelApp.Quit();
Marshal.ReleaseComObject(excelApp);
What else should I do to properly shutdown the excel process?
many Thanks.
Here is my code:
Microsoft.Office.Interop.Excel.Application excelApp=null;
Microsoft.Office.Interop.Excel.Workbook newWorkbook =
null;
Microsoft.Office.Interop.Excel.Sheets excelSheets = null;
Microsoft.Office.Interop.Excel.Worksheet sheet = null;
try
{
excelApp = new
Microsoft.Office.Interop.Excel.ApplicationClass();
//openExcelDoc.InitialDirectory =
string.Format(@"{0}Carweb", drives[0]);
excelApp.Visible = false;
newWorkbook =
excelApp.Workbooks.Open(templateExcelPath, 0, false, 5, "", "", false,
Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false,
0, true, false, false);
excelSheets = newWorkbook.Worksheets;
foreach (Microsoft.Office.Interop.Excel.Worksheet
excelWorksheet in excelSheets)
{
string name = excelWorksheet.CodeName;
name = excelWorksheet.Name;
}
}
finally
{
if (sheet != null)
{
Marshal.ReleaseComObject(sheet);
}
if (excelSheets != null)
{
Marshal.ReleaseComObject(excelSheets);
}
if (newWorkbook != null)
{
newWorkbook.Close(Missing.Value, Missing.Value,
Missing.Value);
Marshal.ReleaseComObject(newWorkbook);
}
if (excelApp != null)
{
excelApp.Quit();
Marshal.ReleaseComObject(excelApp);
}
I did following code to open an excel sheet and now just close it. But
the problem is that the excel process created in my code is still
there when I use:
excelApp.Quit();
Marshal.ReleaseComObject(excelApp);
What else should I do to properly shutdown the excel process?
many Thanks.
Here is my code:
Microsoft.Office.Interop.Excel.Application excelApp=null;
Microsoft.Office.Interop.Excel.Workbook newWorkbook =
null;
Microsoft.Office.Interop.Excel.Sheets excelSheets = null;
Microsoft.Office.Interop.Excel.Worksheet sheet = null;
try
{
excelApp = new
Microsoft.Office.Interop.Excel.ApplicationClass();
//openExcelDoc.InitialDirectory =
string.Format(@"{0}Carweb", drives[0]);
excelApp.Visible = false;
newWorkbook =
excelApp.Workbooks.Open(templateExcelPath, 0, false, 5, "", "", false,
Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false,
0, true, false, false);
excelSheets = newWorkbook.Worksheets;
foreach (Microsoft.Office.Interop.Excel.Worksheet
excelWorksheet in excelSheets)
{
string name = excelWorksheet.CodeName;
name = excelWorksheet.Name;
}
}
finally
{
if (sheet != null)
{
Marshal.ReleaseComObject(sheet);
}
if (excelSheets != null)
{
Marshal.ReleaseComObject(excelSheets);
}
if (newWorkbook != null)
{
newWorkbook.Close(Missing.Value, Missing.Value,
Missing.Value);
Marshal.ReleaseComObject(newWorkbook);
}
if (excelApp != null)
{
excelApp.Quit();
Marshal.ReleaseComObject(excelApp);
}