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