WSH query data results directly into EXCEL tables

Source: Internet
Author: User
Tags chr goto
' Excela.vbs ' directly to query the results of the data generated EXCEL table, a little modification can be
' Change to ASP file on server to customer
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 "Database link is not smooth!;"
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 "Query statement wrong!;"
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&AMP;CHR (9) &rs (i). Name
Next
RSNAME=RSNAME&AMP;CHR (13)
Dim strdate
Strdate=rsname&rs. GetString (2,-1,,, "")
If Err.Number <> 0 Then
WScript.Echo "Error saving data!;"
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 "Create file Error!;"
End If

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.