Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Set fso = CreateObject("Scripting.FileSystemObject") ' paths'n'shit
- ' Parse command line args
- Set cmd_args = WScript.Arguments
- If cmd_args.Count = 1 Then
- filename_in = fso.GetAbsolutePathName(cmd_args(0))
- Else
- WScript.Echo("Invalid number of arguments. Use as: cscript export.vbs <xlsx_file>")
- WScript.Quit 1
- End If
- ' Check input file
- If Not fso.FileExists(filename_in) Then
- WScript.Echo("Input file " & filename_in & " not found.")
- WScript.Quit 2
- End If
- With CreateObject("Excel.application")
- With .Application
- .Visible=false ' don't draw shit
- .DisplayAlerts=false ' overwrite without asking
- .DecimalSeparator = "."
- .ThousandsSeparator = ""
- .UseSystemSeparators = false
- End With
- .Workbooks.Open(filename_in) ' first one becomes .ActiveWorkbook
- .ActiveSheet.Unprotect
- For Each cell in .ActiveSheet.UsedRange.Cells
- If IsNumeric(cell) Then
- cell.NumberFormat = "@" ' Text
- ElseIf IsDate(cell) Then
- 'cell.Value = DateDiff("s", "1/1/1970", cell.Value) ' Unix timestamp
- cell.NumberFormat = "yyyy-mm-dd hh:mm:ss" ' Random shit
- End If
- Next
- ' Save
- With .ActiveWorkbook
- filename_out = fso.BuildPath(.Path, fso.GetBaseName(.Name))
- .SaveAs filename_out, 62 ' 62 = xlCSVUTF8
- End With
- .Application.Quit
- .Quit
- End With
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement