vb.net 读/写 Excel 文件 Visual Studio 2017

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45472555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 20:19:17  来源:igfitidea点击:

Read/Write Excel files Visual Studio 2017

excelvb.net

提问by RicRev

I just installed Microsoft Office 2010 (I'm guessing this has some references the program needs), and I'm using Visual Studio Community 2017, what reference do I need to add to write and read .xslx files?

我刚刚安装了 Microsoft Office 2010(我猜这有一些程序需要的参考),并且我使用的是 Visual Studio Community 2017,我需要添加什么参考来写入和读取 .xslx 文件?

Edit: The Microsoft Excel 14.0 reference just appeared on the COM list, but I still can't make a file. I'm guessing I need to import something now?

编辑:Microsoft Excel 14.0 参考刚刚出现在 COM 列表中,但我仍然无法创建文件。我猜我现在需要导入一些东西?

回答by D_Bester

This assumes you actually got the reference added as you state.

这假设您确实按照您的陈述添加了参考。

So then add this at the top of the code window

所以然后在代码窗口的顶部添加这个

Imports Microsoft.Office.Interop

导入 Microsoft.Office.Interop

and this in your code:

这在你的代码中:

Dim objApp As New Excel.Application
objApp.Visible = True

https://support.microsoft.com/en-us/help/302094/how-to-automate-excel-from-visual-basic--net-to-fill-or-to-obtain-data

https://support.microsoft.com/en-us/help/302094/how-to-automate-excel-from-visual-basic--net-to-fill-or-to-obtain-data

回答by PDKnight

I'm using vb.net (Visual Studio 15) and have MS Office 16, and when I added the COM reference Microsoft Excel 16.0 Object Library to my project, it didn't take. I actually had to browse (in the add reference window) to the following location an add a dll:

我正在使用 vb.net (Visual Studio 15) 并有 MS Office 16,当我将 COM 引用 Microsoft Excel 16.0 对象库添加到我的项目时,它没有用。我实际上不得不浏览(在添加引用窗口中)到以下位置并添加一个 dll:

C:\Windows\assembly\GAC_MSIL\microsoft.office.interop.excel\15.0.0.0_71be9bcellle9429c\microsoft.office.interop.excel.dll

C:\Windows\assembly\GAC_MSIL\microsoft.office.interop.excel\15.0.0.0_71be9bcellle9429c\microsoft.office.interop.excel.dll