16,718
社区成员
发帖
与我相关
我的任务
分享
objSheet.Cells(i, 1).GetType.ToString
objSheet.Range("b1").Value.ToString
dim str as string ="ABCDEFG"
objSheet.Range(str.chars(i) & j).Value.ToString
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\项目\读入数据\bukao.mdb"
cn.Open()
cmd.ActiveConnection = cn
Dim objExcel As Microsoft.Office.Interop.Excel.Application
Dim objBook As Microsoft.Office.Interop.Excel.Workbook
Dim objSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim strPicName As String
Dim OpenFileDialog1 As New OpenFileDialog()
OpenFileDialog1.ShowDialog()
strPicName = OpenFileDialog1.FileName
objExcel = CreateObject("Excel.Application")
objBook = objExcel.Workbooks.Open(strPicName) '代表excel?
objExcel.Visible = True
objSheet = objBook.Worksheets(1)
Dim nRows As Integer
nRows = objExcel.Sheets(1).UsedRange.Rows.Count
Dim i As Integer
Try
For i = 1 To nRows
rs = New ADODB.Recordset
cmd.CommandText = "insert into bkstudent values('" & objSheet.Cells(i, 1).GetType.ToString & " ','" & objSheet.Cells(i, 2).GetType.ToString & " ','" & objSheet.Cells(i, 3).GetType.ToString & " ','" & objSheet.Cells(i, 1).GetType.ToString & " ')"
rs = cmd.Execute
Next
cn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub