码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-05-10 03:43:27      阅读:375      评论:0      收藏:0      [点我收藏+]

标签:des   style   ext   color   c   get   


‘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

WSH 直接将查询数据结果生成 EXCEL 表,布布扣,bubuko.com

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

标签:des   style   ext   color   c   get   

原文地址:http://blog.csdn.net/u014739768/article/details/25423109

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!