c# - 如何从功能区 ExcelDNA 中检索控件
问题描述
我想知道您如何能够从 ExcelDNA 生成的 .dna 文件中定义的自定义 RibbonUI 中检索控件?目前我正在实施一个登录工作流程,其中一个按钮被禁用。用户将在哪里登录,如果成功将启用禁用按钮。
解决方案
Office 功能区界面完全基于回调。因此,您实际上无法从功能区“检索控件”并在这些控件上设置属性。您通过触发回调来实现状态更改 - 在这种情况下可能是您的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(); }
}
}
推荐阅读
- c++ - 我应该如何修复这段代码,其中我需要打印斐波那契数列中的前 n 个数字?(C++)
- c++ - 从叶子和池计算证书链
- maven - 插件 org.apache.maven.plugins:maven-clean-plugin:3.1.0 或其依赖项之一无法解析:
- javascript - 节点强大默认上传目录路径
- database - 如何使用 JPA 和 H2 数据库在删除时强制执行外键约束
- javascript - 在初始化变量之前评估带有模板文字的测试名称
- python - 有没有办法通过在文本框中输入的索引来删除列表中的元素
- c++ - C++ 类没有被初始化
- php - 如何在 condorcet 中设置选票?
- android - react-native-community/语音识别会很快自动停止