我一直在研究下面的代码一段时间。我正在尝试将组合框绑定到 Sheet1 列 A6 下来。我制定了以下代码,但在查找声明的文件时遇到问题。我检查了文件的名称,甚至复制和粘贴,但它仍然找不到它。
Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.Office.Interop.Excel
Public Class dsbPositionBoard
Private ConnectionNoHeader As String = "provider=Microsoft.Jet.OLEDB.4.0; data source='{0}';Extended Properties=""Excel 8.0;IMEX=1; HDR=No;"""
Private Sub dsbPositionBoard_Startup() Handles Me.Startup
Dim oExcel As New Microsoft.Office.Interop.Excel.Application
Dim oBook As Microsoft.Office.Interop.Excel.Workbook
Dim oSheet As Microsoft.Office.Interop.Excel.Worksheet
oBook = oExcel.Workbooks.Open("2011.1004.Salary Survey Template.xlsm")
oSheet = CType(oBook.Worksheets(1), Microsoft.Office.Interop.Excel.Worksheet)
Using MyConnection As New System.Data.OleDb.OleDbConnection(String.Format(ConnectionNoHeader, oBook))
MyConnection.Open()
Dim da As New OleDbDataAdapter( _
"SELECT DISTINCT * FROM [Sheet1$A1:A]", MyConnection)
Dim dt As New System.Data.DataTable
da.Fill(dt)
cmbSelectPosition.DisplayMember = dt.Columns(0).ColumnName
cmbSelectPosition.DataSource = dt
'ediDate = dateComboBox.SelectedItem.ToString()
End Using
End Sub