zoukankan      html  css  js  c++  java
  • C# 关闭 Excel进程


    namespace ExcelTest
      {
          class DataOutput
          {
              static void Main(string[] args)
              {
                  Excel.Application app = new Excel.ApplicationClass();
                  Excel.Workbook wBook = app.Workbooks.Add(true);
                  Excel.Worksheet wSheet = wBook.Worksheets[1] as Excel.Worksheet;
                app.Visible = true;

                Kill(app);

                Console.Read();
            }

            [DllImport("User32.dll", CharSet = CharSet.Auto)]
            public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);

            public static void Kill(Excel.Application excel)
            {
                IntPtr t = new IntPtr(excel.Hwnd);   //得到这个句柄,具体作用是得到这块内存入口

                int k = 0;
                GetWindowThreadProcessId(t, out k);   //得到本进程唯一标志k
                 System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k);   //得到对进程k的引用
                 p.Kill();     //关闭进程k
     
             }
         }
    }

  • 相关阅读:
    hbase distributed setup and configuration
    代码优化 性能调优
    正则表达
    [转载]Java&.Net虚拟机精简(GreenJVM&GreenDotNet发布)
    [JQuery]一款不错的jquery验证框架
    js特效集
    jQuery滚动插件2 jCarousel
    c3p0连接池
    php5 apache config
    jQuery滚动插件 (轮播)
  • 原文地址:https://www.cnblogs.com/hdl217/p/3378151.html
Copyright © 2011-2022 走看看