【问题标题】:Excel-DNA, issue with firing Ribbon's onAction code. F#Excel-DNA,触发 Ribbon 的 onAction 代码时出现问题。 F#
【发布时间】:2020-04-12 19:45:31
【问题描述】:

我正在使用 Excel 2010 并尝试在 F# 中运行 Excel-DNA/Samples code 以进行功能区自定义。

<tab id='CustomTab' label='My F# Tab'>
   <group id='SampleGroup' label='My Sample Group'>
        <button id='Button1' label='Run a macro' onAction='RunTagMacro' tag='showMessage' />    <!-- works fine -->
        <button id='Button3' label='Dump the Excel Version to cell A1' onAction='OnDumpData'/>  <!-- DOES NOT WORK -->

Button1 的操作有效,在第 14 行放置断点按预期工作。

但是 Button3 的操作 OnDumpData 没有。我可以看到代码永远不会被调用,因为放置在第 45 行的断点永远不会被命中。

member this.OnDumpData (control:IRibbonControl) =
    let app = ExcelDnaUtil.Application :?> Application  // line 45. Breakpoint here is never reached.
    let cellA1 = app.Range("A1")

我首先认为这可能是版本问题,我尝试将 cutomUI 行 (#26) .../office/2006/01... 替换为 .../office/2009/07...,但问题仍然存在。

我错过了什么(设置或其他东西......)?如何让 Button3 正确触发 OnDumpData 代码?

编辑1: 正如示例文件中所建议的那样,我打开了Excel 选项“显示加载项用户界面错误”选项(在“常规”下的“高级”选项卡下)。我在按下 Button3 时收到的错误消息是:

An exception occurred while calling function "OnDumpDate". Exception message is :
Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.

... 然后我注意到,当我关闭调试 Excel 表时,我在 VS 的输出窗口 ExcelDna.Integration Warning: 1 : Assembly OFFICE could not be loaded from resources. 中收到此消息。这可能是相关的,但我不完全确定在哪里解决这个问题。

【问题讨论】:

    标签: f# ribbon excel-dna


    【解决方案1】:

    听起来您需要在项目中添加对 Office.dll 程序集的引用。这只是与 COM 相关的 PIA 程序集(如 Microsoft.Office.Interop.Excel)。

    要么直接添加到您的项目中,要么安装名为“ExcelDna.Interop”的 NuGet 包,其中包含此库并且也应添加引用。

    【讨论】:

    • 感谢 Govert。我安装了 NuGet 包 ExcelDna.Interop,它现在就像一个魅力。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-04
    • 1970-01-01
    相关资源
    最近更新 更多