Select to view content in your preferred language

Using the Office Primary Interop Assemblies with ArcGIS Pro addins

512
2
07-05-2023 09:47 AM
FenuxLabs
New Contributor

I need to create Excel spreadsheets while inside an ArcGIS Pro Addin Button. Can't seem to get it to work like it did in the 'old' days with ArcObjects. Here's a short Button module that fails... This code is using the Office Primary Interop Assemblies reference. 

 

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports ArcGIS.Core.CIM
Imports ArcGIS.Core.Data
Imports ArcGIS.Core.Geometry
Imports ArcGIS.Desktop.Catalog
Imports ArcGIS.Desktop.Core
Imports ArcGIS.Desktop.Editing
Imports ArcGIS.Desktop.Extensions
Imports ArcGIS.Desktop.Framework
Imports ArcGIS.Desktop.Framework.Contracts
Imports ArcGIS.Desktop.Framework.Dialogs
Imports ArcGIS.Desktop.Framework.Threading.Tasks
Imports ArcGIS.Desktop.Layouts
Imports ArcGIS.Desktop.Mapping
Imports Microsoft.Office.Interop


Friend Class Button1
Inherits Button

Private oExcelApp As Microsoft.Office.Interop.Excel.Application = New Microsoft.Office.Interop.Excel.Application

Protected Overrides Sub OnClick()

Try

' oExcelApp = New Microsoft.Office.Interop.Excel.Application

Dim xlsServiceListingWorkbook As Microsoft.Office.Interop.Excel.Workbook
xlsServiceListingWorkbook = oExcelApp.Workbooks.Add

MsgBox("here")

Catch ex As Exception
MsgBox(ex.ToString)

End Try

End Sub
End Class

Here's the highlights of the error caught in the exception...

Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'.  ......  Element not found (0x8002802B).

The error is thrown at xlsServiceListingWorkbook = oExcelApp.Workbooks.Add. 

Is using COM assembly references a 'no-no' in Pro buttons? 

What would be the best way to read/write spreadsheets from inside the Pro Button code?

 

 

Tags (2)
0 Kudos
2 Replies
AzharIbrahim
New Contributor III

 I'm having trouble getting ClosedXML working in an ArcGIS Pro 3.0.3 Addin. I'm still testing different options, so hopefully someone has a solution. 

0 Kudos