2013-02-19 28 views
6

Tôi gặp sự cố khi cố gắng đặt nhãn tùy chỉnh khi di chuyển bằng ruy-băng bằng Excel-DNA.Không thể thay đổi nhãn trên dải băng excel

Nếu tôi không bao gồm chú thích "getLabel = 'GetLabel'" thì plugin tải tốt. tức là tab ribbon được hiển thị với 2 nút và nút gọi lại hoạt động tốt.

Nếu tôi đưa thuộc tính "getLabel = 'GetLabel'" thì plugin thậm chí không tải, tức là onLoad không được gọi và tab ribbon không hiển thị trong excel.

Có ai có thể thấy những gì tôi đang làm sai ở đây không. Tôi không thấy bất kỳ lỗi nào khi chạy trong trình gỡ lỗi.

Đây là tệp DNA của tôi. Tôi đã cố gắng để căn cứ nó ra một trong các mẫu để nó dễ dàng hơn để làm theo.

<DnaLibrary Name="Emsx Addin" RuntimeVersion="v2.0"> 
<ExternalLibrary Path="EmsxExcelTech1.dll" /> 
<Reference AssemblyPath="System.Windows.Forms.dll" /> 

<!-- Some images that can be used in the Ribbon ui --> 
<Image Name="M" Path="M.png" Pack="true" /> 

<CustomUI> 
<customUI xmlns='http://schemas.microsoft.com/office/2009/07/customui' loadImage='LoadImage' onLoad='OnLoad'> 
    <ribbon> 
    <tabs> 
     <tab id='CustomTab' label='K2 Emsx' insertAfterMso='View'> 
     <group id='SampleGroup' label='Global Sheet Status'> 
      <button id='LoginCmd' label='Logon' image='M' onAction='OnLogonPressed' getLabel='GetLabel' /> 
      <button id='BetaCmd' label='Use Beta Route' image='M' size='normal' onAction='RunTagMacro' tag='OnUseBetaRoutes' /> 
     </group > 
     </tab> 
    </tabs> 
    </ribbon> 
</customUI> 
</CustomUI> 
</DnaLibrary> 

Đây là tệp C# có nguồn gốc từ Ribbon của tôi.

[ComVisible(true)] 
public class EmsxRibbon : ExcelRibbon 
{ 
    private IRibbonUI ribbon = null; 

    public void OnLogonPressed(IRibbonControl control) 
    { 
     EmsxIntegration.Instance.Login(); 
     MessageBox.Show("Hello from control " + control.Id); 
     if (ribbon != null) 
     { 
      ribbon.InvalidateControl(control.Id); 
     } 

    } 

    string GetLabel(IRibbonControl control) 
    { 
     if (control.Tag == "Logon") 
     { 
      return "Logon"; 
     } 
     else 
     { 
      return "Logoff"; 
     } 
    } 

    public static void OnUseBetaRoutes() 
    { 
     MessageBox.Show("Hello from 'ShowHelloMessage'."); 
    } 

    public void OnLoad(IRibbonUI ribbon) 
    { 
     this.ribbon = ribbon; 
    } 

} 
+1

Có thể bạn không có "nhãn" và "nhãn getLabel" trong xml? – Govert

Trả lời

8

Khi bạn sử dụng các sự kiện getLabel, bạn không nên sử dụng tài sản nhãn, vì vậy thay đổi

<button id='LoginCmd' label='Logon' image='M' onAction='OnLogonPressed' getLabel='GetLabel' /> 

để

<button id='LoginCmd' image='M' onAction='OnLogonPressed' getLabel='GetLabel' /> 

Hope this helps.

+0

Cảm ơn bạn đã đăng một giải pháp. Tôi đã thực hiện sửa lỗi tương tự này trong mã cục bộ của mình và quên mất câu hỏi này – chollida

Các vấn đề liên quan