Excel C#二次开发学习笔记01

1. 新建项目

image-20210604100959300

2.会自动生成以下代码,不要修改

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Excel;

namespace ExcelAddIn1
{
    public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO 生成的代码

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

3.在项目右键添加新项

image-20210604101333901

4. 添加一个Button,并添加事件

image-20210604101516022

        private void button1_Click(object sender, RibbonControlEventArgs e)
        {
            MessageBox.Show("Hello Excel Form C#");
        }

5.点击启动按钮会打开Excel,新建一个文件

image-20210604101648974

6. Excel插件建立好了之后,还需要给别人的电脑安装使用才行,这个时候就需要用到VS的发布功能了,然后我们点击项目右键发布功能,会弹出一个发布向导:

image-20210604102417611

image-20210604102431010

image-20210604102847288

7.安装后的效果

image-20210604103012853