使用QTP从excell表中拷贝数据到数据库表中 [ 光影人像 东海陈光剑 的博客 ]
'----------------------------------------------
' 函数名称: InsertFromTable(datasource,fold,sheet,row)
' 作用: 从excell表中插入数据到指定的数据表
' 参数说明: datasource: 指定的数据库名称
' fold: excell文件目录
' sheet: 指定的sheet,sheet名称为数据表的名称
' ' row= all ,那么插入该sheet下的所有行数据
' row =2 ,3等序数,则插入数据指定的行数
'----------------------------------------------
Sub InsertFromTable(datasource,fold,sheet,row)
Set excell = CreateObject("Excel.Application")
excell.Visible = false
excell.WorkBooks.Open(fold)
excell.WorkSheets(sheet).Activate
'得到该sheet的总列数
col = excell.worksheets(sheet).UsedRange.columns.count
'得到该sheet的总行数
If row = "all" Then
rows = excell.WorkSheets(sheet).UsedRange.Rows.Count
For indexi = 2 to rows
strSql = ""
For indexj = 1 to col
If indexj = col Then
strSql = strSql +"'" + CStr(excell.Cells(indexi, indexj).Text) + "'"
else
strSql = strSql + "'" + CStr(excell.Cells(indexi, indexj).Text) + "',"
End If
Next
'插入数据的sql
sql = "insert into " + sheet + " values(" + strSql + ")"
Call InsertOne(datasource,sql)
Next
else
For index = 1 to col
If index = col Then
strSql = strSql +"'" + CStr(excell.Cells(row, index).Text) + "'"
else
strSql = strSql + "'" + CStr(excell.Cells(row, index).Text) + "',"
End If
Next
sql = "insert into AUCTION_BUYER_ANONY values(" + strSql + ")"
Call InsertOne(datasource,sql)
End If
excell.ActiveWorkbook.Close(0)
excell.Quit()
End Sub
如要在dbc中插入数据,则可以使用下面的方法:
fold = "d:\test.xls"
sheet = "AUCTION_BUYER_ANONY"
call InsertFromTable(devdbc,fold,sheet,"all")
据说,男人看美图可以延年益寿,女人看美图可以美容养颜........
那么, 去哪儿看美图呢? 亲爱的,别急!别急!! 在这里---
欢迎关注! 光影人像 公众号!
光影人像---和美不期而遇.
( 摄影 艺术 人像 美图 )
Copyright 2015 光影科技公司版权所有
回复 1 : 首页
回复 2 : 影廊
回复 3 : 社区
回复 4 : 下载App
回复 5 : 精选文章列表
lightshadow 光影人像 Abstract 抽象艺术 Macro 微距 Animals 动物 Nature 自然 Black and White 黑白 People 人像 Celebrities 节日 Performing Arts 行为艺术 City 城市 Architecture 建筑 Sport 运动 Commercial 商业摄影 Life 生活 Concert Street Family 家庭 Transportation Fashion 时尚 Travel 旅行 Film 电影 Underwater 水下 Fine Art Urban 乡间 Exploration Food 美食 Wedding 婚纱 Journalism Uncategorized 杂类 Landscapes 风景