|
套用风过无息的代码,写了个小程序,可是程序执行完成之后打开excel文件,却发现什么数据也没有。
'创建excel对象
Set ExcelObject = createobject("excel.application")
'指定excel格式
aatype = "f:\templet.xls"
'打开excel
ExcelObject.WorkBooks.open(aatype)
'设置操作得工作表
Set NewSheet = ExcelObject.Sheets.item(2)
'以下是数据库操作
Dim rs,conn,sql
Set conn = createobject("adodb.connection")
Set rs = createobject("adodb.recordset")
conn.open="Provider=OraOLEDB.Oracle.1;Password=hdjb;Persist Security Info=True;User ID=hdjb;SERVER=172.16.1.45;Data Source=1.45;DBQ=;"
sql = "select aac001,aac003 from ac01"
rs.open sql,conn
i = 1
Do while rs.eof
values1 = rs("aac001")
values2 = rs("aac003")
NewSheet.Cells(i+1,1).value = values1
NewSheet.Cells(i+1,2).value = values2
i = i +1
rs.movenext
Loop
'保存excel数据
ExcelObject.ActiveWorkBook.Saveas "f:\data.xls"
ExcelObject.Quit
Set ExcelObject = Nothing
rs.close
Set rs=nothing
Set conn = nothing |
|