我尝试使用 VB6.0 中的 Excel 库参考来读取 excel。
当数据导出到 SQL 表时,SSIS 导入向导将 NUMERIC 视为 NULL。
此过程非常适用于数据插入以及其他数据库操作。
私有子访问ExcelData()
出错时转到 errHandler
Dim oXLApp As Excel.Application'声明对象变量
将 oXLBook 调暗为 Excel.Workbook
将 oXLSheet 调暗为 Excel.worksheet
将 strFileName 调暗为字符串
Dim lCount As Long
将 strSCDName 调暗为字符串
将 strICDName 作为字符串变暗
将 intSource_Index 调暗为整数
将 strInput_Port 调暗为字符串
将 strLabel 调暗为字符串
将 strSDI_CID 调暗为字符串
将 intWordBitNO 调暗为整数
将 strFilter_Type 调暗为字符串
将 strPgroup_Input 调暗为字符串
暗淡 strParagraph_Input 作为字符串
将 strSQL 暗淡为字符串
将 sConnString 调暗为字符串
将 cnTest 调暗为新的 ADODB.Connection
将 rsTempRecordset 调暗为新的 ADODB.Recordset
将 objDataAccess 调暗为新的 FmmtDataAccess.clsDataAccess
将 strxmlResult 调暗为字符串
objDataAccess.Intialize ConString
strFileName = App.Path & "\IODE.xls"
sConnString = "Server=uasql\commonsql;Database=accounts;Driver=SQL Server;Trusted_Connection=Yes;DSN=uasql\commonsql"
使用 cnTest
.ConnectionString = sConnString
.ConnectionTimeout = 4
.CursorLocation = adUseClient
.打开
以
结尾
' 创建部分 Excel 工作表。
设置 oXLApp = CreateObject("Excel.Application")
'创建一个新的 Excel 实例
oXLApp.Visible = False
'不要显示给用户
Set oXLBook = oXLApp.Workbooks.Open(strFileName) '打开现有工作簿
Set oXLSheet = oXLBook.Worksheets(1) '使用第一个工作表oXLSheet.Activate
使用 oXLApp
对于 lCount = 2 到 oXLSheet.UsedRange.Rows.Count
strSCDName = .Cells(lCount, 1).Value
strICDName = .Cells(lCount, 2).Value
intSource_Index = .Cells(lCount, 3).Value
strInput_Port = .Cells(lCount, 4).Value
strLabel = .Cells(lCount, 5).Value
strSDI_CID = .Cells(lCount, 6).Value
intWordBitNO = .Cells(lCount, 7).Value
strFilter_Type = .Cells(lCount, 8).Value
strPgroup_Input = .Cells(lCount, 9).Value
strParagraph_Input = .Cells(lCount, 10).Value
'strSQL = "插入XYX()值(strSCDName .....) 这里可以使用任何数据库相关的查询
rsTempRecordset.Open strSQL, cnTest, adOpenForwardOnly, adLockReadOnly Next
结束
' 关闭部分 Excel 工作表。
oXLApp.Visible = False '不向用户显示它
Set oXLSheet = Nothing '断开与所有 Excel 对象的连接(让用户接管)
oXLBook.Close SaveChanges:=False '保存(并断开)工作簿
设置 oXLBook = 无
oXLApp.Quit '关闭(并断开连接)Excel
设置 oXLApp = 无
退出 SuberrHandler:
MsgBox Err.Description
Screen.MousePointer = vbNormalEnd Sub
通过此程序,可以从 vb 应用程序中读取 excel 记录,并可以将其插入到 SQL 数据库中的现有表中。
谢谢
撞锤