excel interop - 如何运行 excel com 加载项代码

发布于 2024-11-26 10:13:49 字数 113 浏览 1 评论 0原文

我有一个我创建的 Excel 插件。 我想要做的是在 C# (ASP.NET) 中打开 Excel 文档并在加载项中运行一些代码,然后将 Excel 文档作为 html 页面返回。

这可以做到吗?

I have an excel add-in i created.
What i want to do is to open an excel document in c# (ASP.NET) and run some code in the add-in and then return the excel document as an html page.

Can this be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我一向站在原地 2024-12-03 10:13:49

在 Com 加载项中,我必须添加:

public partial class ThisAddIn
{
    ...
    protected override object RequestComAddInAutomationService()
    {
         if (addinUtilities == null)
         {
              addinUtilities = new AddinUtilities();
         }
         return addinUtilities;
    }
...
}

您应该从此函数返回一个对象,该对象稍后可以在互操作中使用,如下面的代码片段所示。添加您想要公开给该对象的任何功能。

然后按如下方式使用插件:

Application app = new Application();
var myAddin = app.COMAddIns;
var count = myAddin.Count;
COMAddIn addin;
for (int i = 1; i <= count ; i++) // not zero indexed
{
    addin = myAddin.Item(i);
    var ob = addin.Object;
    var str = addin.ProgId;
    if (ob != null)
    {
         ob.RunQuery(ws);
    }
}

如您所见,我还没有找到一种识别我的插件的好方法(如果有人知道我想听到的),但您可以迭代它们并检查 progId。

addin.Object 是我们从 RequestComAddInAutomationService 返回的对象。

In the Com add-in i had to add:

public partial class ThisAddIn
{
    ...
    protected override object RequestComAddInAutomationService()
    {
         if (addinUtilities == null)
         {
              addinUtilities = new AddinUtilities();
         }
         return addinUtilities;
    }
...
}

You should return an object from this function, this object can later be used in interop as in the code snippet below. add any functionality you want to expose to this object.

Then use the addin as follows:

Application app = new Application();
var myAddin = app.COMAddIns;
var count = myAddin.Count;
COMAddIn addin;
for (int i = 1; i <= count ; i++) // not zero indexed
{
    addin = myAddin.Item(i);
    var ob = addin.Object;
    var str = addin.ProgId;
    if (ob != null)
    {
         ob.RunQuery(ws);
    }
}

As you can see i have not found a good way of identifying my add-in (if anybody knows of one i would like to hear), but you can iterate over them and check the progId.

addin.Object is the object we returned from RequestComAddInAutomationService.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文