【问题标题】:Excel ribbon doesn't show up with excel-dnaExcel 功能区不显示 excel-dna
【发布时间】:2016-12-14 23:24:30
【问题描述】:

尝试使用 excel-dna 和 C# 创建功能区。加载加载项时,功能区不显示在 Excel 中。

dna 文件:

<DnaLibrary Name="falcon" RuntimeVersion="v4.0">
<ExternalLibrary Path="bin/Debug/falcon.dll" />
<!--<Reference AssemblyPath="System.Windows.Forms.dll" />-->

<CustomUI>
<customUI xmlns='http://schemas.microsoft.com/office/2009/07/customui' onLoad='OnLoad'>
  <ribbon>
    <tabs>
      <tab id='CustomTab' label='My Tab' insertAfterMso='View'>
        <group id='SampleGroup' label='My Group'>
          <button id='LoginCmd' onAction='OnLogonPressed' label='logon' />
        </group >
      </tab>
    </tabs>
  </ribbon>
</customUI>
</CustomUI>
</DnaLibrary>

cs 文件:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExcelDna.Integration;
using System.Runtime.InteropServices;
using ExcelDna.Integration.CustomUI;

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

        public void OnLogonPressed(IRibbonControl control)
        {
            if (ribbon != null)
            {
                ribbon.InvalidateControl(control.Id);
            }

        }

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

    }
}

我使用 Visual Studio 社区版,代码使用 .NET 4.6 编译。我通过直接单击 xll 文件或将其加载到新的 excel 文件中来加载加载项。在 excel 中,加载项选项卡已启用,并且宏安全性处于最低级别。此外,我在Settings > Advanced 下启用了显示 UI 加载项的所有错误的选项。我使用 excel 2010。

当我打开 excel 时,功能区既不显示也不显示错误消息。大家有什么建议吗?

【问题讨论】:

  • 它可以在我的机器上运行(虽然还没有用 4.6 检查),所以功能区标记和代码是正确的。我建议添加一个简单的 UDF(甚至可以作为 Ribbon 中的静态函数)来确认加载项实际上正在加载。 (宏安全设置可能会阻止它完全加载)。除此之外,如果可以,请检查另一台计算机,并查看 Excel 中可能会阻止加载 COM 加载项的安全设置。
  • 哦 - 您在 ExternalLibrary 中的 Path="..." 看起来不对。 .dll 不在 .xll 旁边吗?也许从一个新的类库项目开始,然后安装“Excel-DNA”NuGet 包。
  • 我使用了 Visual Studio externalLibrary 项目和 NuGet 包。之后一切都很完美——我可以使用 bin 文件夹中的文件和 F5 开始调试。感谢 cmets govert!

标签: excel-dna


【解决方案1】:

我也遇到过类似的问题,但是在我制作 assembly ComVisible 之后它也可以工作:

[<assembly: ComVisible(true)>]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多