Is there a way to generate excel report in c# using interop excel with version indepent? - office-interop

I am using Visual Studio 2019 and installed "Microsoft.Office.Interop.Excel V 15.0.4795.1000" using Nuget.
When I generating excel report it is working fine with "Microsoft Office 2013". But, getting error message with "Microsoft Office Home and Business 2019".
Error Message : Exception from HRESULT: 0x800A03EC Exception : System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC
I assume that Interop Excel V 15 is not supporting with office 2019.
I used below code to create excel application.
using ExApp = Microsoft.Office.Interop.Excel;
ExApp.Application xlApp = new ExApp.Application();
Later, I also tried with below code thinking that it will work with multiple versions of excel.
Type ExcelType = Type.GetTypeFromProgID("Excel.Application");
dynamic xlApp = Activator.CreateInstance(ExcelType);
Is there a way we can generate excel report in c# on any version of excel (2007 to 2019)?
At least, I need solution for "Microsoft Office Home and Business 2019".

Related

Excel connection manager error - importing from Table to Excel

I am getting below error while selecting Excel file after configuring connection manager.
I am using visual studio 2019 and Excel 2016.
Where am I going wrong?
Thanks
Ar

Calling Access Report from VS 2013 Express Throws ActiveX Error

I have a VS 2013 Express system that uses an Access db. After populating the db with values, I open a report object created in Access. This all worked perfectly approximately 1 year ago. Now, in development or production, trying to open the report throws an error.
The code behind the form is:
Imports Access = Microsoft.Office.Interop.Access
Public Class frmReports
Public db_path As String
Dim oAccess As Access.application
And the code behind the button that opens the report is:
Private Sub btnSumByPlan_Click(sender As Object, e As EventArgs) Handles btnSumByPlan.Click
oAccess = CreateObject("Access.Application")
oAccess.visible = True
oAccess.opencurrentdatabase(db_path)
oAccess.docmd.openreport(ReportName:="rptSumByPlan", view:=Access.AcView.acViewPreview)
End Sub
However the code fails on the CreateObject line with the following error:
An unhandled exception of type 'System.Exception' occurred in Microsoft.VisualBasic.dll.
Additional information: Cannot create ActiveX component.
I have the following COM references selected:
Microsoft Access 12.0 Object Library
Microsoft ActiveX Data Objects 2.8 Library
Microsoft Office 12.0 Object Library
Microsoft Visual Basic for Applications Extensibility 5.3
I have tried selecting different versions of the Access, Office and ActiveX libraries but still get the same error.
I'm not positive, but I think I was running Office 2010 a year ago and now Office 2013.
Can you tell me what I'm doing wrong?
Thanks in advance.

Office 2010 Shared PIA is not Available?

I have an Excel Add-In for Excel-2010 version, which was created using Microsoft Visual Studio 2010.
The code is written in C#. To install the Add-In , you have to run a setup.exe file which will add the Add-In to Excel.
Everything seems to be working fine on Excel 2010, but when I am trying to install this on Excel-2103
I am getting the following Error:
The Office 2010 Shared PIA System is not Available.
Is there a way to install the add-in in the 2013 and also after it is installed will it work Perfectly or do i need to make any changes ?
It took a while to figure out but its done finally.
The add in launch conditions were checking for the availability of the shared PIA.
Condition: HASSHAREDPIA
and it was looking for the corresponding component id associated with excel 2013 PIA component ID
Click Here https://social.msdn.microsoft.com/Forums/vstudio/en-US/1fd8690a-812c-49f9-a77e-e19f24de7c4e/office-2013-pia-component-ids?forum=vsto
to obtain the suitable component id and replace it in the
Search Target Machine
Search for office 2010 shared PIA.
and replace the component id.
the add in should be working fine.

Get DTE for VS2010 addin using VB?

I am converting a Visual Studio 2010 macro to work in an addin. I am using VB. How do I correct the line below:
Dim win As Window = DTE.ActiveWindow
which gives this error:
Error 3 Reference to a non-shared member requires an object
reference. C:\Users\Frank\documents\visual studio
2010\Projects\MyAddin2\MyAddin2\Module1.vb 28
The DTE is passed via the Application parameter in IDTExtensibility2.OnConnection. This method is called when the AddIn is initialized by Visual Studio.
The AddIn project wizard should have generated some code that casts the Application parameter to a field of type DTE2. Use that field to access the ActiveWindow property.

Connection string not working when saving to 2007 format

I'm very confused with OleDB & Excel.
I've 2 files:
One is saved in Excel 2007
One is saved in Excel 2010
This is because some computers have 2007 and other 2010 version of Microsoft Excel.
In vb.net i use:
m_sConn1 = String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='{0}';Extended Properties='Excel 12.0;HDR=NO;IMEX=1';", file)
When is do:
conn1 = New System.Data.OleDb.OleDbConnection(m_sConn1)
conn1.open()
With the save-in-2010 file i got 0 errors.
With the one saved in 2007 i got
"External table is not in the expected format"
Is this string connection for both versions? Should i use Interop instead? (because the file is auto generated using Interop Excel 12.0 and it works in 2007 & 2010).
I already installed 2007 Office System Driver: Data Connectivity Components from http://www.microsoft.com/en-us/download/details.aspx?id=23734
Edit:
If i open the 2007 file in 2010 and save it, oleDB reads it ok.
It's a Bug already reported. Only Excel 2007 has this error and MS knows it but never addressed it.
This project can be only use w/ excel 2007.

Resources