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
     
             }
         }
    }

  • 相关阅读:
    linux基础名词
    计算机基础
    c++ 构造函数
    c++ stdafx.h、targetver.h文件
    centos7初步命令
    mysql 操作表的语句
    后台返回API数据格式
    nginx相关知识
    js复制内容到剪贴板格式化粘贴到excel中
    PHP开启错误提示
  • 原文地址:https://www.cnblogs.com/hdl217/p/3378151.html
Copyright © 2011-2022 走看看