VSTO入门 (一) 建立测试工程

来源:互联网 发布:怎么用淘宝客买东西 编辑:程序博客网 时间:2024/06/13 07:33

163博客迁移!

首先如果没有安装VSTO, 需要打开控制面板,找到VS2015之类的,更改,然后安装Office开发


安装好之后,会有Visual C# -->office/sharePoint --->Word 2013 VSTO 外接程序(这个是作用所有的主机上的word文档), (另外还有, -->Word 2013 VSTO的工作薄和模板,都会创建出一个doc的文档,VSTO只是针对该文档的,不是整个主机的)

1. 直接工程名写入,然后自动出现代码,  例如:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Word;
using System.Windows.Forms;        -----注意: MessageBox.Show()函数需要添加这个,不然编译不过。

namespace FirstDocumentCustomization1
{
    public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            MessageBox.Show("你好!你打开了word!");
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            MessageBox.Show("你好!你退出了word!");
        }

        #region VSTO 生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要修改
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }
}
直接按F5运行就可以了。

原创粉丝点击