GoodBoyNYC
GoodBoyNYC

Reputation: 159

How to open Excel in vb.net

I followed this site to get me started on my program, here

When I add the reference and declare my variables:

Imports Excel = Microsoft.Office.Interop.Excel
Class XCel
    Dim xlApp As New Excel.Application
    Dim xlWorkBook As Excel.Workbook
    Dim xlWorkSheet As Excel.Worksheet
End Class

I get an ambiguity error, " 'Application' is ambiguous in the namespace 'Microsoft.Office.Interop.Excel' "

I've read a few pages saying to remove the reference then re-add it and updating the PIAs but none have helped.

Is there a simpler way to open an Excel? Something I'm missing in my code/project to get it to work?

Upvotes: 0

Views: 2994

Answers (1)

Eric J.
Eric J.

Reputation: 150108

Is there a simpler way to open an Excel?

The EPPlus open source project makes it much easier to work with Excel files than using Office Interop:

EPPlus is a .net library that reads and writes Excel 2007/2010 files using the Open Office Xml format (xlsx).

http://epplus.codeplex.com/

I get an ambiguity error, " 'Application' is ambiguous in the namespace 'Microsoft.Office.Interop.Excel' "

I ran into the same error that you are getting now when I had PIA's for more than one Office version installed on the same machine. I ended up resolving it by only installing the newest version of Excel on my development machine (because after all, I wanted to have the newest version of Office for general work) and creating a Virtual Machine that had the oldest version of Office that I needed to support that I used as a build machine to do the final release build and create the setup program for customers.

Upvotes: 1

Related Questions