读取Excel 文件的问题...
上图先,Excel 的对象取得里面出现了很多的错误...
代码如下,
Imports Microsoft.Office.Interop.Excel
Imports Microsoft.Office.Interop
Private Sub StartPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartPrint.Click
On Error GoTo errorline
Dim xlApp As New Application
Dim xlBook As Workbook
Dim xlSheet As Worksheet
xlApp = GetObject(, "Excel.Application")
If Err.Number() <> 0 Then
Err.Clear()
xlApp = CreateObject("Excel.Application")
If Err.Number() <> 0 Then
MsgBox("Have not installed Excel")
End
End If
End If
xlBook = xlApp.Workbooks.Open("C:\123.xls")
xlApp.DisplayAlerts = False
xlApp.Visible = True
xlBook.Activate()
xlBook.Parent.Windows(1).Visible = True
xlSheet = xlBook.Worksheets(WORKSHEETNAME)
...........................
问题到底在哪里呢?
[解决办法]
项目中添加引用COM组件Microsoft.Office.Interop.Excel就OK了
全名为Microsoft.Office.Interop.Excel.dll
vs2010用你的代码测试通过