首页 > 系统服务 > 详细

导出excel后关闭excel进程

时间:2017-01-19 16:07:22      阅读:188      评论:0      收藏:0      [点我收藏+]
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);

worksheet.SaveAs(filePath, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault);
            book.Close(true, null, null);          

            System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(book);
            excel.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);

            if (excel != null)
            {
                try
                {
                    int lpdwProcessId;
                    GetWindowThreadProcessId(new IntPtr(excel.Hwnd), out lpdwProcessId);
                    System.Diagnostics.Process.GetProcessById(lpdwProcessId).Kill();
                }
                catch (Exception ex1)
                {
                }
            }

            worksheet = null;
            book = null;
            excel = null;
            
            GC.Collect();            

 

导出excel后关闭excel进程

原文:http://www.cnblogs.com/ToddLai/p/6307004.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!