I am rather new here. I have search this forum and I saw that double dot a COM object is not good, I have changed the open() to one dot. But I am still unable to kill off the processes. Added the Marshal.ReleaseComObject and it still didn't work. Anybody can point out the error in my code? Thanks.
Application excel = new Application();
try
{
//excel.Workbooks.Open(filePath); //Apparently double dot for COM object is not a good practice
var excelworkbooks = excel.Workbooks;
var openworkbook = excelworkbooks.Open(filePath);
excel.Visible = false;
if (excel.Workbooks.Count > 0)
{
IEnumerator wsEnumerator = excel.ActiveWorkbook.Worksheets.GetEnumerator();
object format = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml;
while (wsEnumerator.MoveNext())
{
Microsoft.Office.Interop.Excel.Worksheet wsCurrent = (Microsoft.Office.Interop.Excel.Worksheet)wsEnumerator.Current;
String outputFile = "OutputFile.html";
if(!File.Exists(filePath+outputFile))
{
wsCurrent.SaveAs(filePath + outputFile, format);
}
break;
}
}
excel.Workbooks.Close();
excel.Application.Quit();
excel.Quit();
Marshal.ReleaseComObject(excelworkbooks);
Marshal.ReleaseComObject(openworkbook);
}
finally
{
Marshal.ReleaseComObject(excel.Workbooks);
Marshal.ReleaseComObject(excel.Application);
Marshal.ReleaseComObject(excel);
}