Convert XLS to CSV on command line

后端 未结 15 2335
臣服心动
臣服心动 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:45

    A slightly modified version of ScottF answer, which does not require absolute file paths:

    if WScript.Arguments.Count < 2 Then
        WScript.Echo "Please specify the source and the destination files. Usage: ExcelToCsv  "
        Wscript.Quit
    End If
    
    csv_format = 6
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    src_file = objFSO.GetAbsolutePathName(Wscript.Arguments.Item(0))
    dest_file = objFSO.GetAbsolutePathName(WScript.Arguments.Item(1))
    
    Dim oExcel
    Set oExcel = CreateObject("Excel.Application")
    
    Dim oBook
    Set oBook = oExcel.Workbooks.Open(src_file)
    
    oBook.SaveAs dest_file, csv_format
    
    oBook.Close False
    oExcel.Quit
    

    I have renamed the script ExcelToCsv, since this script is not limited to xls at all. xlsx Works just fine, as we could expect.

    Tested with Office 2010.

提交回复
热议问题