Dim x As Integer
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim AppExcel As New Excel.Application
Set AppExcel = CreateObject("Excel.Application")'创建Excel对象
Set xlBook = AppExcel.Workbooks.Open("D:\数据表.xls") '打开工作簿
If AppExcel Is Nothing Then Exit Sub'错误则退出
For x = 1 To AppExcel.Sheets.Count '找到对应的工作表
If AppExcel.Sheets(x).Name ="工作表名" Then
Set xlSheet = AppExcel.Sheets(x)
Exit For
End if
Next
'下面为单元格的定义
xlSheet.Cells([RowIndex],[ColumnIndex]).Value'单元格(行 , 列)
xlSheet.Range("B2:B2").Value'单元格选择
Set xlSheet = Nothing
Set xlBook = Nothing
Set AppExcel = Nothing
End Sub
'VB6.0必需先引用Microsoft Excel 11.0 Object Library
Set xlApp = CreateObject("Excel.Application") '激活EXCEL应用程序xlApp.Visible = False '隐藏EXCEL应用程序窗口
Set xlBook = xlApp.Workbooks.Open(FileManually) '打开工作簿,FileManually为一个EXCEL报表文件
Set xlSheet = xlBook.Worksheets(Trim(txtSheetNM.Text)) '设定工作表
For IRowsCount = 1 To xlSheet.UsedRange.Cells.Rows.Count
If Trim(xlSheet.Cells(IRowsCount, 1)) = "" Then
Exit For
End If
'将xlSheet.Cells(IRowsCount,列号)的数据插入数据库中
'转换男女可以判断xlSheet.Cells(IRowsCount,列号)="男",则=1,否则=0,然后再写入数据库
Next IRowsCount
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)