码迷,mamicode.com
首页 > 其他好文 > 详细

C#打开Excel并响应客户端自动化事件

时间:2014-12-10 17:53:17      阅读:315      评论:0      收藏:0      [点我收藏+]

标签:io   ar   os   sp   for   on   art   log   cti   

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using MSExcel = Microsoft.Office.Interop.Excel;

namespace word
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
MSExcel.Application excelApp;
MSExcel.Workbook book;


private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog P_GetFile = new OpenFileDialog();
DialogResult P_dr = P_GetFile.ShowDialog();
object obj = (object)(P_GetFile.FileName);
if (P_dr == DialogResult.OK)
{
excelApp = new MSExcel.Application();
book = excelApp.Application.Workbooks.Add(obj);
excelApp.Visible = true;
}
excelApp.WorkbookBeforeSave += new MSExcel.AppEvents_WorkbookBeforeSaveEventHandler(excelApp_WorkbookBeforeSave);
}
private void excelApp_WorkbookBeforeSave(MSExcel.Workbook Wb, bool SaveAsUI, ref bool Cancel)
{
MessageBox.Show("hello Excel");
}
}
}

C#打开Excel并响应客户端自动化事件

标签:io   ar   os   sp   for   on   art   log   cti   

原文地址:http://www.cnblogs.com/lemeng/p/4155873.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!