Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我在Windows窗体应用程序中遇到以下错误?有人能帮忙解决吗_C#_.net_Excel_Windows_Forms - Fatal编程技术网

C# 我在Windows窗体应用程序中遇到以下错误?有人能帮忙解决吗

C# 我在Windows窗体应用程序中遇到以下错误?有人能帮忙解决吗,c#,.net,excel,windows,forms,C#,.net,Excel,Windows,Forms,从excel上传数据并将其存储在gridview中,然后关闭应用程序,执行所有任务后,将出现以下弹出窗口 已编写excel wokbook和excel工作表关闭的代码 i、 e:sWorkbook.Close(); sExcelApp.Quit() 以上消息是由于您的excel对象未关闭,它仍保留在系统进程中 实际上,您可以干净地释放Excel应用程序对象,但必须小心。 通过Marshal.finalEleaseComObject()访问并显式释放的COM对象在理论上是正确的,但不幸的是,在实践

从excel上传数据并将其存储在gridview中,然后关闭应用程序,执行所有任务后,将出现以下弹出窗口

已编写excel wokbook和excel工作表关闭的代码 i、 e:sWorkbook.Close();
sExcelApp.Quit()

以上消息是由于您的excel对象未关闭,它仍保留在系统进程中

实际上,您可以干净地释放Excel应用程序对象,但必须小心。 通过
Marshal.finalEleaseComObject()
访问并显式释放的COM对象在理论上是正确的,但不幸的是,在实践中很难管理

// Cleanup
GC.Collect();
GC.WaitForPendingFinalizers();

Marshal.FinalReleaseComObject(xlRng);
Marshal.FinalReleaseComObject(xlSheet);

xlBook.Close(Type.Missing, Type.Missing, Type.Missing);
Marshal.FinalReleaseComObject(xlBook);

xlApp.Quit();
封送员最终电子对象(xlApp); 在大多数从.NET清理COM对象的代码示例中,
GC.Collect()
GC.WaitForPendingFinalizers()
调用的次数是中的两倍:

GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();

请向我们展示与使用Excel对象模型中的任何内容相关的所有代码。