我正在保存到excel文件的链接,但是一旦我保存了它,excel进程仍然在运行。我应该如何重新发布这个excel com对象?
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook book = app.Workbooks.Add(1);
Microsoft.Office.Interop.Excel.Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)book.Worksheets[1];
for (int i = 0; i < Links.Count; i++)
{
sheet.Cells[i + 1, 1] = Links[i];
}
book.SaveAs("test.xlsx");
Marshal.ReleaseComObject(sheet);
sheet = null;
book.Close(true, null, null);
Marshal.ReleaseComObject(book);
book = null;
app.Quit();
Marshal.ReleaseComObject(app);
app = null;发布于 2013-08-12 00:06:26
也许"sheet.Cells“是一个你必须发布的引用:
var cells = sheet.Cells;
...
Marshal.ReleaseComObject(cells);https://stackoverflow.com/questions/18173569
复制相似问题