Scott Lock

Thoughts on .Net, Caparea.net and Windows Phone


News

My Stats

  • Posts - 77
  • Comments - 134
  • Trackbacks - 21

Tag Cloud


Recent Comments


Recent Posts


Archives


Post Categories


Image Galleries


Blogs I Read


Microsoft MVP


User Groups



This has been posted in the newsgroups a few times, but really is required when adding dynamic controls.  If you are trying to get references to the managed (Excel.Tools) object, this is the way to go.  This creates a new managed worksheet object that has a controls collection that you can then use.  Here is the basic code for the function:

internal Microsoft.Office.Tools.Excel.Worksheet GetExtendedWorksheet(
            ref Microsoft.Office.Interop.Excel.Worksheet nativeWorksheet) {

            // Get the IHostItemProvider instance.
                Microsoft.VisualStudio.Tools.Applications.Runtime.IHostItemProvider hostItemProvider =
                    (Microsoft.VisualStudio.Tools.Applications.Runtime.IHostItemProvider)(RuntimeCallback.GetService(typeof(Microsoft.VisualStudio.Tools.Applications.Runtime.IHostItemProvider)));

                // Create the new worksheet and return it to calling function.
               
return new Microsoft.Office.Tools.Excel.Worksheet(hostItemProvider,
                            RuntimeCallback,
                            nativeWorksheet.CodeName,
                            Container,
                            nativeWorksheet.Name
);
           }


Comments

Gravatar # Getting an instance of the managed container for an interop object in Excel 2003 using VSTO 2005
Posted by HIMANSHU on 8/23/2007 8:20 AM
Hi ,

I want to make a excel add –in.

I tried to use Microsoft.Office.Tools.Excel.Controls Namespace but for this we require Tools.Excel.Controls.worksheet object. But when we make Excel add-in we get Microsoft.Office.Interop.Excel.Worksheet object. I have tried to convert Excel.Worksheet object to Controls.worksheet object. Basically we require host object to contain controls. So I have used object of Microsoft.VisualStudio.Tools.Applications.Runtime.IHostItemProvider that convert Excel.Worksheet object to Controls.worksheet object but when I have implemented addButton method to convert object its give an error message.



So please help me as soon as possible……



Thanks and Regard,

Himanshu Jain

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: