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

C#打开word 编辑后保存时自动化响应

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

标签:io   ar   os   sp   for   on   文件   art   log   

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 MSWord=Microsoft.Office.Interop.Word;

 

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

private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog P_GetFile = new OpenFileDialog(); //创建打开文件对话框对象
DialogResult P_dr = P_GetFile.ShowDialog(); //显示打开文件对话框
object oMissing = System.Reflection.Missing.Value;
if (P_dr == DialogResult.OK) //是否单击确定
{
wordApp = new MSWord.Application();
wordApp.Visible = true;
object obj = (object)(P_GetFile.FileName);
wordApp.Documents.Open(ref obj, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
}
wordApp.DocumentBeforeSave += new MSWord.ApplicationEvents4_DocumentBeforeSaveEventHandler(wordApp_DocumentBeforeSave);
}
private void wordApp_DocumentBeforeSave(MSWord.Document doc, ref bool SaveAsUI, ref bool Cancel)
{
MessageBox.Show("hello office");
}
}
}

C#打开word 编辑后保存时自动化响应

标签:io   ar   os   sp   for   on   文件   art   log   

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

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