我有一个wsf脚本,在visual basic中运行,运行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都必须以文本格式更改单元格,我尝试找到一种方法以编程方式执行,没有宏,因为每次脚本运行时都会删除文件并且无法存储宏
有人可以帮助我吗? 谢谢。
答案 0 :(得分:2)