簡體   English   中英

如何從功能區ExcelDNA檢索控件

[英]How to retrieve controls from ribbon 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(); } 
  } 
} 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM