简体   繁体   English

如何在vb.net中打开Excel

[英]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' " 我得到一个模棱两可的错误,“命名空间“ 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. 我读了几页,说要删除引用,然后重新添加并更新PIA,但没有一个起作用。

Is there a simpler way to open an Excel? 有没有更简单的方法来打开Excel? Something I'm missing in my code/project to get it to work? 我的代码/项目中缺少什么才能正常工作?

Is there a simpler way to open an Excel? 有没有更简单的方法来打开Excel?

The EPPlus open source project makes it much easier to work with Excel files than using Office Interop: EPPlus开源项目使使用Excel文件比使用Office Interop容易得多:

EPPlus is a .net library that reads and writes Excel 2007/2010 files using the Open Office Xml format (xlsx). EPPlus是一个.net库,它使用Open Office Xml格式(xlsx)读取和写入Excel 2007/2010文件。

http://epplus.codeplex.com/ http://epplus.codeplex.com/

I get an ambiguity error, " 'Application' is ambiguous in the namespace 'Microsoft.Office.Interop.Excel' " 我得到一个模棱两可的错误,“命名空间“ 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. 当我在同一台计算机上安装多个Office版本的PIA时,遇到了与您现在遇到的错误相同的错误。 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. 最后,我仅在开发机器上安装了最新版本的Excel(毕竟,我想拥有最新版本的Office来进行常规工作)并创建具有所需的最旧版本Office的虚拟机,从而解决了该问题支持我用作构建机器来进行最终版本构建并为客户创建安装程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM