Convert XLS to CSV on command line

后端 未结 15 2322
臣服心动
臣服心动 2020-11-22 12:11

How could I convert an XLS file to a CSV file on the windows command line.

The machine has Microsoft Office 2000 installed. I\'m open to installing OpenOffice if it\

15条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 12:43

    Open Notepad, create a file called XlsToCsv.vbs and paste this in:

    if WScript.Arguments.Count < 2 Then
        WScript.Echo "Error! Please specify the source path and the destination. Usage: XlsToCsv SourcePath.xls Destination.csv"
        Wscript.Quit
    End If
    Dim oExcel
    Set oExcel = CreateObject("Excel.Application")
    Dim oBook
    Set oBook = oExcel.Workbooks.Open(Wscript.Arguments.Item(0))
    oBook.SaveAs WScript.Arguments.Item(1), 6
    oBook.Close False
    oExcel.Quit
    WScript.Echo "Done"
    

    Then from a command line, go to the folder you saved the .vbs file in and run:

    XlsToCsv.vbs [sourcexlsFile].xls [destinationcsvfile].csv
    

    This requires Excel to be installed on the machine you are on though.

提交回复
热议问题