在vb.net中声明/打开excel文件

我一直在尝试一段时间来声明或打开在VB.NET的Excel表。 我已经阅读vb.net和其他链接的Excel文件,但它不工作。

我添加了Microsoft Excel 12.0对象库。 包括我:

Imports Microsoft.VisualBasic Imports System.Net.Mime.MediaTypeNames Imports Microsoft.Office.Interop 

我想声明/打开模块中的excel文件:

 Public Module postleitzahlen_array Dim myarray As String Dim xlApp As Excel.Application xlApp = New Excel.ApplicationClass ' here is the error, XlApp "has to be declared" 

有人能帮我吗?

编辑:

好吧,我注意到我使用Excel 2007,有一个不同 – 现在我使用http://vb.net-informations.com/excel-2007/vb.net_excel_2007_create_file.htm中的 follwing代码

 Sub test() Dim xlApp As Excel.Application Dim xlWorkBook As Excel.Workbook Dim xlWorkSheet As Excel.Worksheet Dim misValue As Object = System.Reflection.Missing.Value xlApp = New Excel.ApplicationClass xlWorkBook = xlApp.Workbooks.Add(misValue) xlWorkSheet = xlWorkBook.Sheets("sheet1") xlWorkSheet.Cells(1, 1) = "http://vb.net-informations.com" xlWorkSheet.SaveAs("D:\vbexcel.xlsx") xlWorkBook.Close() xlApp.Quit() releaseObject(xlApp) releaseObject(xlWorkBook) releaseObject(xlWorkSheet) MsgBox("Excel file created , you can find the file c:\") End Sub Private Sub releaseObject(ByVal obj As Object) Try System.Runtime.InteropServices.Marshal.ReleaseComObject(obj) obj = Nothing Catch ex As Exception obj = Nothing Finally GC.Collect() End Try End Sub 

但我得到xlWorkSheet = xlWorkBook.Sheets("sheet1")一个错误说:“(由HRESULTexception:0x8002000B(DISP_E_BADINDEX))

编辑2:我使用德语excel,所以“sheet1”引发错误 – >“tabelle1”是正确的词:)

这帮助我开始,虽然对于C#。 我怀疑VB的概念是相似的。

至于你的错误,将ApplicationClassreplace成简单的Application已经解决了我的问题。