【发布时间】:2015-07-26 22:00:15
【问题描述】:
好的,所以我做了很多谷歌搜索,试图找到关于这个主题的信息,但我几乎空手而归。也许我没有为我想要完成的事情寻找正确的术语。
我的问题是我在 MS Excel 插件中编写了一个函数,我按照 Microsoft 的说明作为起点,但他们的教程在每次用户保存文档时都会执行代码。我的目标是在我设计的功能区上有一个按钮来执行此功能,而不是保存按钮。
这是我开始关注的 Microsoft 文章:https://msdn.microsoft.com/en-us/library/cc668205.aspx
我也在这里找到了这个问题,但没有足够的细节让我弄清楚如何为自己实施解决方案:How to connect a ribbon button to a function defined in an Excel add-in?
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
{
void FormatTime(Microsoft.Office.Interop.Excel.Workbook WB, bool SaveAsUi, ref bool Cancel)
{
/////MY FUNCTION BODY HERE//////
}
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
提前感谢您的帮助。
【问题讨论】: