首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

weboffice使用有关问题

2012-10-30 
weboffice使用问题调用weboffice在关闭网页后,进程怎么不结束呢?[解决办法]WebOffice每次打开文档,都会有

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

热点排行