|
Set excelObj = CreateObject("Excel.Application") '创建一个对象
xlsUrl = "d:\data001.xls" '指定一个已经存在的XSL 文件路径
excelObj.workbooks.open(xlsUrl) '打开EXCEL
Set sheetNew = excelObj.sheets.item(2) '设置将数据放在EXCEL 中的那一页上(索引从1开始)
'相关的数据库操作
Set conn = CreateObject("adodb.connection")
set rs = createobject("adodb.recordset")
conn.open "Provider=SQLOLEDB.1assword=ping1.28ersist Security Info=True;User ID=sa;Initial Catalog=SSEIS;Data Source=192.168.1.122"
rs.open "select username,password from s_LoginAccount",conn,1,1
Dim i
while not rs.eof
user_id = rs("password").value
user_name = rs("username").value
sheetNew.cells(i+1,1).value = user_id '列付值
sheetNew.cells(i+1,2).value = user_name '列付值
i = i + 1
rs.movenext
wend
excelObj.activeworkbook.saveas "d:\data002.xls" '保存数据,用于存放从数据库读取的username,password
excelObj.quit '关闭对象
set excelObj = nothing '清空对象
rs.close '关闭数据库连接操作
set rs=nothing
conn.close
set conn = nothing
[ 本帖最后由 chenjinxia 于 2010-2-3 09:47 编辑 ] |
|