为了账号安全,请及时绑定邮箱和手机立即绑定

打包的 Excel DNA .xll 文件无法加载功能区

打包的 Excel DNA .xll 文件无法加载功能区

PHP
红颜莎娜 2024-01-20 15:51:49
我尝试部署使用 Excel-DNA 工具构建的 Excel 加载项。从 Visual Studio 运行时,该加载项工作正常,但是,当我尝试从其他地方打开打包的 .xll 文件时,按照 Govert(Excel DNA 的创建者)的建议,功能区中的插件无法加载。激活插件错误消息后,我收到非显式消息:对 GetCustomUI() 的调用失败。就是这样。所以我有两个问题:有没有办法获取有关加载错误插件的更多详细信息,以便了解调用失败的原因(这将是调查的良好开端)?我怀疑错误来自配置文件/资源/图标,这些文件/资源/图标无法正确打包到 xll 文件中。我的 AddIn.dna 文件包含每个引用的 dll 的语句Reference Path="XXX.dll" Pack="true" ,但我应该声明资源吗?还有配置文件?
查看完整描述

2 回答

?
米琪卡哇伊

TA贡献1998条经验 获得超6个赞

我用 try/catch 块包围了 GetCustomUI() 方法重写,并将异常记录到文本文件中。这使我能够访问插件启动时引发的异常。

而且,最重要的是,问题是我有一个额外的 JSON 配置文件,打包的 XLL 没有考虑到该文件,似乎没有直接的方法可以通过 DNA 文件包含它。

将外部文件设置为嵌入资源并从清单资源流中读取它。

在我的特定情况下,我将它用于 DI 服务提供商,并按如下方式构建它:

private IServiceProvider BuildServiceProvider()

    {

        var serviceCollection = new ServiceCollection();


        //Configuration

        ConfigurationBuilder builder = new ConfigurationBuilder();

        builder.SetBasePath(Directory.GetCurrentDirectory());


        var assembly = Assembly.GetExecutingAssembly();

        var resourceName = "otherconfig.json";

        using (Stream stream = assembly.GetManifestResourceStream(resourceName))

        using (StreamReader reader = new StreamReader(stream)) {

            string result = reader.ReadToEnd();

            string tempPath = Path.GetTempFileName();

            File.WriteAllText(tempPath, result);

            builder.AddJsonFile(tempPath);

        }


        IConfiguration config = builder.Build();

        serviceCollection.AddSingleton(config);


        //other dependency injection service registration


        return serviceCollection.BuildServiceProvider();

    }


查看完整回答
反对 回复 2024-01-20
?
aluckdog

TA贡献1847条经验 获得超7个赞

如果您要重写该方法GetCustomUI,请添加try...catchon GetCustomUI,然后查看异常详细信息。


[ComVisible(true)]

public class RibbonController : ExcelRibbon

{

    public override string GetCustomUI(string RibbonID)

    {

        try

        {

             // ...

        }

        catch(Exception ex)

        {

             MessageBox.Show(ex.ToString());

        }

    }


    // ...

}


查看完整回答
反对 回复 2024-01-20
  • 2 回答
  • 0 关注
  • 83 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信