>Microsoft.Office.Interop.Excel.Application oXL; >Microsoft.Office.Interop.Excel._Workbook oWB; >Microsoft.Office.Interop.Excel._Worksheet oSheet; > >oXL = new Microsoft.Office.Interop.Excel.Application(); >oWB = (Microsoft.Office.Interop.Excel._Workbook)(oXL.Workbooks.Add(Missing.Value)); >oSheet = (Microsoft.Office.Interop.Excel._Worksheet)oWB.ActiveSheet; > >Reader = new StreamReader(ExportParams.sSourceFileName); > >iRow = 0; >sSourceRow = Reader.ReadLine(); > >while (sSourceRow != null) >{ > iRow++; > string[] aWords = sSourceRow.Split(','); > > oSheet.Cells[iRow, 1] = aWords[0]; > oSheet.Cells[iRow, 2] = aWords[1]; > oSheet.Cells[iRow, 3] = aWords[2]; > > sSourceRow = Reader.ReadLine(); >} > >Reader.Close(); > >if (File.Exists(ExportParams.sResultFileName)) >{ > File.Delete(ExportParams.sResultFileName); >} > >oSheet.SaveAs(ExportParams.sResultFileName, > Type.Missing, > Type.Missing, > Type.Missing, > Type.Missing, > Type.Missing, > Type.Missing, > Type.Missing, > Type.Missing, > Type.Missing); > >oXL.Quit();Probably it is related to Excel misbehaviour at oXL.Quit().
oXL.Quit() System.Runtime.InteropServices.Marshal.ReleaseComObject(oXL) oXL = NothingBecause of the above, I would not declare objects like oWB and oSheet. They should be closed one by one and in proper parent-child order before closing Excel. I would work with oXl.ActiveWorkbook, and oXl.ActiveSheet instead.