如何从功能区 ExcelDNA 中检索控件
How to retrieve controls from ribbon ExcelDNA
我想知道您如何能够从 ExcelDNA 生成的 .dna 文件中定义的自定义 RibbonUI 检索控件?目前我正在实施一个登录工作流程,其中一个按钮被禁用。用户登录的位置,如果成功将启用禁用的按钮。
Office 功能区界面完全基于回调。所以你实际上不能从功能区 'retrieve controls' 并设置这些属性。您通过触发回调来实现状态更改 - 在这种情况下可能是您的 getEnabled
回调。
要触发功能区的失效,以便再次评估您的回调,请在加载功能区时获得的功能区界面上调用 Invalidate。
一些实现此功能的 C# 代码可能如下所示:
public class MyRibbon: ExcelRibbon
{
private static IRibbonUI _ribbonUi;
// This ribbon xml can be returned in code, or places in the .dna file
public override string GetCustomUI(string uiName)
{
return
@"
<customUI onLoad='Ribbon_Load'
xmlns='http://schemas.microsoft.com/office/2006/01/customui'>
<ribbon>
<tabs>
<tab idMso='TabAddIns'>
<group id='group1' label='Group1'>
<button id='button1' getEnabled='btn_GetEnabled' getLabel='btn_GetLabel' />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
";
}
public void Ribbon_Load(IRibbonUI sender)
{
_ribbonUi = sender;
}
public bool btn_GetEnabled(IRibbonControl control)
{
return true;
}
public bool btn_GetLabel(IRibbonControl control)
{
return "My Button";
}
public static void Refresh()
{
if (_ribbonUi != null) { _ribbonUi.Invalidate(); }
}
}
我想知道您如何能够从 ExcelDNA 生成的 .dna 文件中定义的自定义 RibbonUI 检索控件?目前我正在实施一个登录工作流程,其中一个按钮被禁用。用户登录的位置,如果成功将启用禁用的按钮。
Office 功能区界面完全基于回调。所以你实际上不能从功能区 'retrieve controls' 并设置这些属性。您通过触发回调来实现状态更改 - 在这种情况下可能是您的 getEnabled
回调。
要触发功能区的失效,以便再次评估您的回调,请在加载功能区时获得的功能区界面上调用 Invalidate。
一些实现此功能的 C# 代码可能如下所示:
public class MyRibbon: ExcelRibbon
{
private static IRibbonUI _ribbonUi;
// This ribbon xml can be returned in code, or places in the .dna file
public override string GetCustomUI(string uiName)
{
return
@"
<customUI onLoad='Ribbon_Load'
xmlns='http://schemas.microsoft.com/office/2006/01/customui'>
<ribbon>
<tabs>
<tab idMso='TabAddIns'>
<group id='group1' label='Group1'>
<button id='button1' getEnabled='btn_GetEnabled' getLabel='btn_GetLabel' />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
";
}
public void Ribbon_Load(IRibbonUI sender)
{
_ribbonUi = sender;
}
public bool btn_GetEnabled(IRibbonControl control)
{
return true;
}
public bool btn_GetLabel(IRibbonControl control)
{
return "My Button";
}
public static void Refresh()
{
if (_ribbonUi != null) { _ribbonUi.Invalidate(); }
}
}