我有一个 wsf 脚本,在 Visual Basic 中为 vritten,它运行 db2 查询并将结果保存在文件 .csv 中。
Function CreaCSVdaSQL (SQL,fileCompletePath)
Dim Input , conn,rs,csvtext,fso,fs,line
set conn = CreateObject ("ADODB.Connection")
conn.open _
"Provider=SQLOLEDB.1;Initial Catalog=XXXX;Data Source=XXXXX;MARS Connection=True;User Id=XXXX;password=XXXX"
set rs = conn.execute (SQL)
line = ""
Dim tmp
For Each tmp In rs.Fields
line=line & tmp.Name & ";"
Next
if (Not rs.EOF) then
csvText = line & vbcrlf & rs.getString (2,, ";", VBCrLf)
rs.close: set rs = nothing
conn.close: set conn = nothing
Dim l_sn
l_sn = Replace (Now, "-", "")
l_sn = Replace (l_sn, ":", "")
l_sn = Replace (l_sn, "", "")
set fso = CreateObject ("Scripting.FileSystemObject")
set fs = fso.CreateTextFile (fileCompletePath, true)
fs.writeline (csvText)
fs.close: set fs = nothing
set fso = nothing
end if
End Function
每次我的同事用 excel 打开文件 csv 都必须更改文本格式的单元格,我尝试找到一种方法以编程方式进行,没有宏,因为每次脚本运行时文件都会被删除并且无法存储宏。
有人可以帮助我吗?谢谢。