0

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?

4

1 回答 1

1

有没有更简单的方法来打开 Excel?

EPPlus 开源项目使得使用 Excel 文件比使用 Office 互操作更容易:

EPPlus 是一个 .net 库,它使用 Open Office Xml 格式 (xlsx) 读取和写入 Excel 2007/2010 文件。

http://epplus.codeplex.com/

我收到一个模棱两可的错误,“'Application' 在命名空间 'Microsoft.Office.Interop.Excel' 中是模棱两可的”

当我在同一台机器上安装多个 Office 版本的 PIA 时,我遇到了与您现在遇到的相同的错误。我最终解决了这个问题,只在我的开发机器上安装了最新版本的 Excel(因为毕竟,我想拥有最新版本的 Office 用于一般工作)并创建一个具有我需要的最旧版本 Office 的虚拟机支持我用作构建机器来进行最终版本构建并为客户创建安装程序。

于 2012-08-27T17:33:46.230 回答