Monday, 26 August 2013

change cell properties from an excel file open with a wsf script

change cell properties from an excel file open with a wsf script

i have a wsf script, vritten in visual basic, that run a db2 query and
save the results in a file .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
Everytime my collegue open the file csv with excel have to change the cell
in text format, i try to find a way to do it programmatically, without a
macro, because the file is deleted everytime the script run and cannot
store the macro.
Somebody can help me ? Thanks.

No comments:

Post a Comment