读书人

weboffice使用有关问题

发布时间: 2012-10-30 16:13:36 作者: rapoo

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();    }
[解决办法]
学习...还没用过这个东东。

读书人网 >C#

热点推荐