环境:win10、vs2019、excel2019
ThisAddIn.cs代码
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 ExcelAddIn3
{
public partial class ThisAddIn
{
public Excel.Application ExcelApp;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
ExcelApp = Globals.ThisAddIn.Application;
ExcelApp.ActiveCell.Value = "hello";
}
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
}
}
正常来说,在程序启动之后,会打开一个新的excel窗体(这里是正常的),但是,窗体打开后,并没有加载代码中的内容,也没有出现新添加的选项卡,貌似连startup也没有进去,不知道是出了什么问题。
程序执行后的Excel:
加载项可能被你禁止掉了,你可以在设置里面勾选显示。同样地,微软也默认隐藏掉了【开发工具】选项,你应该能够在设置里面找到。
已解决:各位如果有遇到这样的问题,可以检查一下注册表的信息,查看是否有对应的addin项,还有一种情况是用了release方式启动,如果之前已经安装过该插件,使用release方式会加载不出来,更换成debug方式就可以了