Microsoft.Office.Interop.Excel API 应用(一)ExcelApplication
来源:互联网 发布:lightgallery.js 编辑:程序博客网 时间:2024/05/16 16:10
1. 项目中添加引用“Microsoft.Office.Interop.Excel” ;
2. 添加using “”using Microsoft.Office.Interop.Excel;
Code:
using System.Threading;using System.Runtime.InteropServices;using System.Diagnostics;using System;using Microsoft.Office.Interop.Excel;namespace OfficeUtility{ /// <summary> /// Start an excel process with some parameters setting /// </summary> public class ExcelApp : IDisposable { [DllImport("user32.dll")] static extern int GetWindowThreadProcessId(int hWnd, out int lpdwProcessId); private Application excelAppInstance = null; public Application ExcelAppInstance { get { return excelAppInstance; } } /// <summary> /// Create an new excel app instance /// </summary> /// <param name="visible">true if excel object is visible; otherwise visible.</param> public ExcelApp(bool visible) { Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); excelAppInstance = new Microsoft.Office.Interop.Excel.Application(); excelAppInstance.Visible = visible; } /// <summary> /// Create an new excel app instance /// </summary> /// <param name="visible">true if excel object is visible; otherwise visible.</param> /// <param name="displayAlerts">true if permit excel app displays certain alerts and messages while a macro is running; otherwise false.</param> public ExcelApp(bool visible, bool displayAlerts) { Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); excelAppInstance = new Microsoft.Office.Interop.Excel.Application(); excelAppInstance.Visible = visible; excelAppInstance.DisplayAlerts = displayAlerts; } #region IDisposable Members /// <summary> /// Kill the excel process /// </summary> public void Dispose() { if (excelAppInstance != null) { int processId; //Call windows API get processId of the current excel app GetWindowThreadProcessId(excelAppInstance.Hwnd, out processId); excelAppInstance.Quit(); Thread.Sleep(5000); Process p = Process.GetProcessById(processId); if (p != null) { try { p.Kill(); } catch (Exception) { } } } } #endregion }}
- Microsoft.Office.Interop.Excel API 应用(一)ExcelApplication
- Microsoft.Office.Interop.Excel API应用(二) Workbook
- 我的Office PIA之路(一) Microsoft.Office.Interop.Excel.dll 的获取
- Microsoft.Office.Interop.Excel出现的问题(转)
- 引用Microsoft.Office.Interop.Excel的解决方法
- 求解Microsoft.Office.Interop.Excel.Application引用
- ” Microsoft.Office.Interop.Excel”无法引用
- Microsoft.Office.Interop.Excel的用法
- Microsoft.Office.Interop.Excel的用法
- Microsoft.Office.Interop.Excel的用法
- Microsoft.Office.Interop.Excel的用法
- Microsoft.Office.Interop.Excel列宽自适应
- 关于C#操作EXCEL,生成图表的全面应用之一(利用Microsoft.Office.Interop.Excel)
- NPOI读写Excel 或 Microsoft.Office.Interop.Excel 读取excel
- 关于C#操作EXCEL,生成图表的全面应用之二(利用Microsoft.Office.Interop.OWC11)
- 引用Microsoft.Office.Interop.Excel.dll操作Excel常用方法
- Microsoft.Office.Interop.Excel 打开的Excel进程的关闭
- C# 结合Microsoft.Office.Interop.Excel写入Excel
- QT 移植
- 《算法导论》笔记--霍夫曼(Huffman)树构造
- application和session的区别
- 邻接矩阵存储
- Javascript实现阳历转阴历
- Microsoft.Office.Interop.Excel API 应用(一)ExcelApplication
- ffmpeg 静态库太大,只要h264,mpeg4
- 内存一致性错误和线程干扰
- myeclipse利用axis1.4发布webservice
- Android中SQLite应用详解
- android实例分析(转)
- varnish pipe 和pass的区别分析
- [转帖]短信猫软件的实现(C#)熟悉串口
- sql 范式 转