VSTO 以编程方式添加基于现有工作表的新工作表
我目前有一个 C# 工作簿级 Office 2007 插件,它具有工作表在设计时添加,我已将方法和属性添加到 Worksheet 派生类。
我希望能够以编程方式创建一个新工作表,自动克隆、继承或以其他方式拥有此现有 Worksheet 类的方法和事件处理程序。
如果可以实现这一点,那么有人可以概述一下如何实现这一点吗?尽管任何 .NET 代码都可以接受,但最好使用 C# 演示代码。
谢谢您的宝贵时间。
I currently have a C# Workbook-level Office 2007 Addin that has a Worksheet added at design-time where I have added methods and properties to the Worksheet derived class.
I want to be able to programatically make a new worksheet that clones, inherits or otherwise possesses the methods and event handlers of this existing Worksheet class automatically.
If this can be achieved then please could someone outline how this could be achieved? C# demo code would be preferably although any .NET code would be acceptable.
Thank-you for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,问得好,我会密切关注这里发生的事情。
几个月前,我遇到了类似的问题,需要在动态创建的工作表上创建代码和事件。然而,为了能够做到这一点,我最终在工作表中创建了 VBA 脚本对象。
所以过程是:
Ok, good question, and I'll be keeping an eye on what comes up on here.
A few months ago, I had a similar problem, and needed to create code and events on dynamically created sheets. To be able to do that, however, I ended up creating VBA script objects within the sheet.
So the process was:
我现在得出的结论是,按照我所寻找的那样在现有状态下复制这些类实际上是不可行的。
根据主机项和主机控件概述:在文档级插件中,主机项不能以编程方式创建,只能在设计时创建。主机项的对编程限制的进一步说明中强化了这一点和主机控件,特别是对于文档级插件。
I've now come to the conclusion that it's not actually feasible to duplicate these classes in their existing state as I was looking for.
According to the Host Items and Host Controls Overview: in Document Level Addins, Host Items cannot be created programmatically but only at design time. This is reinforced in the further explanation of the programmatic limitations of Host items and host controls, particularly for document level addins.