代码之家  ›  专栏  ›  技术社区  ›  SeanC

ExcelDna未在加载项中显示自定义功能区

  •  0
  • SeanC  · 技术社区  · 7 年前

    我正在将一个旧的dna文件转换为visual basic。net,以允许在Excel 64位中使用

    用于在32位版本中显示的功能区(用于更改默认值的简单msgbox),但功能区未在新版本中显示。

    我正在使用VS 2017。

    用于创建功能区的代码:

    ' Can make a class that implements ExcelDna.Integration.CustomUI.ExcelRibbon
    ' to get full Ribbon access.
    Public Class MyRibbon
        Inherits ExcelRibbon
    
        Public Sub OnButtonPressed(control As IRibbonControl)
            SetDefault()
        End Sub
    
    End Class
    

    功能区dna文件中的代码:

    <CustomUI>
       <!-- Inside here is the RibbonX xml passed to Excel -->
       <customUI xmlns = "http://schemas.microsoft.com/office/2006/01/customui">
        <ribbon>
          <tabs>
            <tab idMso = "TabAddIns" >
              <group idQ="x:ORSErlang64" label="ORSErlang64">
                <button id="C1" label="Set Default" size="large"
                imageMso="StartAfterPrevious" onAction="OnButtonPressed"/>
    
              </group>
            </tab>
          </tabs>
        </ribbon>
      </customUI>
    </CustomUI>
    

    我不知道我做错了什么,我在网上找到的大多数例子都是c#,而不是vb。网

    1 回复  |  直到 7 年前
        1
  •  2
  •   C. Augusto Proiete    7 年前

    问题是您将组的ID声明为 idQ="x:ORSErlang64" 但您没有声明名称空间 x

    customUI 元素,您需要定义 x个 命名空间,例如 <customUI xmlns="..." xmlns:x="http://yourapp.com">

    例如:

    <DnaLibrary RuntimeVersion="v4.0" Name="Ribbon Tests" Description="Ribbon Tests Description (not used)">
       <![CDATA[
         Imports System.Runtime.InteropServices
         Imports Microsoft.Office.Core
         Imports ExcelDna.Integration.CustomUI
    
         <ComVisible(True)> _
         Public Class MyRibbon
           Inherits ExcelRibbon
    
           Public Sub  OnButtonPressed(control as IRibbonControl)
               MsgBox("My Button Pressed on control " & control.Id,, "ExcelDna Ribbon!")
           End Sub
    
         End Class
       ]]>
    
      <CustomUI>
         <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
                   xmlns:x="http://caioproiete.net">
          <ribbon>
            <tabs>
              <tab idMso="TabAddIns">
                <group idQ="x:ORSErlang64" label="ORSErlang64">
                  <button id="C1" label="Set Default" size="large"
                    imageMso="StartAfterPrevious" onAction="OnButtonPressed" />
                </group>
              </tab>
            </tabs>
          </ribbon>
        </customUI>
      </CustomUI>
    
    </DnaLibrary>
    

    enter image description here