Scott Lock's Blog

Building the .Net Community through Caparea.Net, Consulting, and no sleep
posts - 62, comments - 30, trackbacks - 35

My Links

News

Twitter












Archives

Post Categories

Blogs I Read

Microsoft MVP

User Groups

Getting an instance of the managed container for an interop object in Excel 2003 using VSTO 2005

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
);
           }

Print | posted on Friday, February 09, 2007 10:56 PM |

Feedback

Gravatar

# Getting an instance of the managed container for an interop object in Excel 2003 using VSTO 2005

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
8/23/2007 8:20 AM | HIMANSHU

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 2 and 1 and type the answer here:

Powered by: