question

SinghSg avatar image
0 Votes"
SinghSg asked DanielZhang-MSFT answered

VSTO Excel C# Databinding

Hi,

I'm using VS - 2019 and VSTO for my 2010 office excel add-in development

I'm implementing section 3 from the reference


I'm want to populate data on to excel on button click...
- I have populated data on dataTable
- But can't get pass code below error code...

Code

 using DataTable = System.Data.DataTable;
 using Worksheet = Microsoft.Office.Interop.Excel.Worksheet;
    
    
 Worksheet worksheet = (Worksheet)Globals.Factory.GetVstoObject(
                     Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet
                     );

Error:

 Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).







Appreciate any help!

dotnet-csharpoffice-vsto-com-dev
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@SwatantraSingh-2674
Based on your description, your issues is more related to code, as tag "office-excel-itpro" focuses on general issues about Excel clients, I will remove it. Thanks for your understanding.

0 Votes 0 ·

1 Answer

DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered

Hi SwatantraSingh-2674,
First, the type of the extended object has the same name as the type of the native Office object, but the type is defined in the Microsoft.Office.Tools.Excel or Microsoft.Office.Tools.Word namespace.
To generate a host item for an Excel worksheet, you can refer to the following code:

 Microsoft.Office.Interop.Excel.Worksheet nativeWorksheet =Globals.ThisAddIn.Application.ActiveSheet;
 if (nativeWorksheet != null)
 {
     Microsoft.Office.Tools.Excel.Worksheet vstoSheet = 
         Globals.Factory.GetVstoObject(nativeWorksheet);
 }

More details you can refer to this document.
And the error may say it can't load a DLL.
Generally, a simple Office repair can be performed from the "Add\Remove" program to solve the problem.
If not, please try to delete invalid registry entries left by Office.
Here are some related threads:
Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'
How to solve “Unable to cast COM object of type Microsoft.Office.Interop.Excel.ApplicationClass’ to interface type ‘Microsoft.Office.Interop.Excel._Application’”
Best Regards,
Daniel Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.