搜索文章:

首页  |  Java技术  |  Asp.net  |  Asp编程  |  VC/C++  |  Delphi  |  VB编程

WSH 直接将查询数据结果生成EXCEL表

excela.vbs 直接将查询数据结果生成 excel 表,稍做修改后即可 
改成asp文件放在服务器上面向客户 

option explicit 
dim conn,strconnstring 
set conn = wscript.createobject("adodb.connection") 
on error resume next 
strconnstring ="provider=sqloledb.1;password=up;" & _ 
"persist security info=true;user id=ui;" & _ 
"initial catalog=ucool;" & _ 
"data source=111.111.111.111;connect timeout=15" 
conn.open strconnstring 
if err.number <> 0 then 
wscript.echo "数据库链接不畅!;" 
wscript.quit 
end if 
on error goto 0 
dim rs,sql 
set rs=wscript.createobject("adodb.recordset") 
on error resume next 
sql="select name,dw,dwdz,zw,sex,email from t1 order by id desc" 
rs.open sql, conn 
if err.number <> 0 then 
wscript.echo "查询语句有误!;" 
wscript.quit 
end if 
on error goto 0 
dim rsname,i 
on error resume next 
rsname=rs( 0 ).name 
for i = 1 to rs.fields.count - 1 
rsname=rsname&chr(9)&rs( i ).name 
next 
rsname=rsname&chr(13) 
dim strdate 
strdate=rsname&rs.getstring(2,-1,,," ") 
if err.number <> 0 then 
wscript.echo "保存数据时出错!;" 
wscript.quit 
end if 
set conn=nothing 
set rs=nothing 
on error goto 0 
dim fs,fl,path,ntime 
set fs=wscript.createobject("scripting.filesystemobject") 
path=wscript.scriptfullname 
path=left(path,instrrev(path,"\")) 
ntime=cstr(now) 
ntime=replace(ntime,":","_") 
on error resume next 
set fl=fs.createtextfile(path&ntime&".xls",true) 
fl.write strdate 
if err.number <> 0 then 
wscript.echo "建立文件出错!;" 
end if

()

相关文章:
© 2006   www.java-asp.net