日期:2014-05-17  浏览次数:21013 次

weboffice使用问题
调用weboffice在关闭网页后,进程怎么不结束呢?

------解决方案--------------------
WebOffice每次打开文档,都会有一个新的进程。
所以只要用ProcessName循环进程。判断MainWindowTitle为空的进程就是因为非法关闭而没有释放的进程。


参照
C# code

添加引用:

using System.Runtime.InteropServices; 

 

结束进程代码
   [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int id);

    public void KillExcellProcess(string path)
    {
        Excel.ApplicationClass excel = new Excel.ApplicationClass();//.applicationclass();
        excel.Workbooks.Open(path, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
        IntPtr t = new IntPtr(excel.Hwnd); 
        int k = 0;
        GetWindowThreadProcessId(t, out k);
        System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k);
        p.Kill();
    }

------解决方案--------------------
学习...还没用过这个东东。