VSTO Programmatically add a new worksheet based on an existing

I currently have a C # Office 2007 Addin that has Worksheet added during development, where I added methods and properties to the Worksheet derived class.

I want to be able to program a new worksheet that clones , inherits, or otherwise has the methods and event handlers of this existing Worksheet strong> class automatically.

If this can be achieved, please can you outline how this can be achieved? C # demo code would be preferable, although any .NET code would be acceptable.

Thank you for your time.

+3
source share
2 answers

Now I have come to the conclusion that it is virtually impossible to duplicate these classes in their existing state, as I was looking for.

According to Host and Host Elements Overview : in adding a document level, host elements cannot be created programmatically, but only during development. This is reinforced by further explaining the software limitations of host elements and host controls, especially for document-level additions.

+1
source

Ok, good question, and I will keep track of what is happening here.

, . , , VBA script .

, :

  • " " Excel
  • #
  • # VBA ..

     oBook = objExcel.ActiveWorkbook;

    oModule = oBook.VBProject.VBComponents.Add(VBIDE.vbext_ComponentType.vbext_ct_StdModule);

    string sCode = "sub myVBASub()\r\n"+
            "msgbox("Hello")\r\n"+
            "End Sub\r\n";

    oModule.CodeModule.AddFromString(sCode);

+2

Source: https://habr.com/ru/post/1720555/


All Articles