欢迎光临
我们一直在努力

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

建站超值云服务器,限时71元/月

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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » WSH 直接将查询数据结果生成 EXCEL 表
分享到: 更多 (0)

相关推荐

  • 暂无文章