Convert XLS to CSV on command line

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

    Why not write your own?

    I see from your profile you have at least some C#/.NET experience. I'd create a Windows console application and use a free Excel reader to read in your Excel file(s). I've used Excel Data Reader available from CodePlex without any problem (one nice thing: this reader doesn't require Excel to be installed). You can call your console application from the command line.

    If you find yourself stuck post here and I'm sure you'll get help.

    0 讨论(0)
  • 2020-11-22 12:36

    I had a need to extract several cvs from different worksheets, so here is a modified version of plang code that allows you to specify the worksheet name.

    if WScript.Arguments.Count < 3 Then
        WScript.Echo "Please specify the sheet, the source, the destination files. Usage: ExcelToCsv <sheetName> <xls/xlsx source file> <csv destination file>"
        Wscript.Quit
    End If
    
    csv_format = 6
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    src_file = objFSO.GetAbsolutePathName(Wscript.Arguments.Item(1))
    dest_file = objFSO.GetAbsolutePathName(WScript.Arguments.Item(2))
    
    Dim oExcel
    Set oExcel = CreateObject("Excel.Application")
    
    Dim oBook
    Set oBook = oExcel.Workbooks.Open(src_file)
    
    oBook.Sheets(WScript.Arguments.Item(0)).Select
    oBook.SaveAs dest_file, csv_format
    
    oBook.Close False
    oExcel.Quit
    
    0 讨论(0)
  • 2020-11-22 12:36

    There's an Excel OLEDB data provider built into Windows; you can use this to 'query' the Excel sheet via ADO.NET and write the results to a CSV file. There's a small amount of coding required, but you shouldn't need to install anything on the machine.

    0 讨论(0)
  • 2020-11-22 12:39

    Building on what Jon of All Trades has provided, the following (~n) removed the pesky double extension issue: FOR /f "delims=" %%i IN ('DIR *.xlsx /b') DO ExcelToCSV.vbs "%%i" "%%~ni.csv"

    0 讨论(0)
  • 2020-11-22 12:41

    A small expansion on ScottF's groovy VB script: this batch file will loop through the .xlsx files in a directory and dump them into *.csv files:

    FOR /f "delims=" %%i IN ('DIR *.xlsx /b') DO ExcelToCSV.vbs "%%i" "%%i.csv"
    

    Note: You may change extension .xlsx to .xls andname of script ExcelToCSV to XlsToCsv

    0 讨论(0)
  • 2020-11-22 12:41

    I tried ScottF VB solution and got it to work. However I wanted to convert a multi-tab(workbook) excel file into a single .csv file.

    This did not work, only one tab(the one that is highlighted when I open it via excel) got copied.

    Is any one aware of a script that can convert a multi-tab excel file into a single .csv file?

    0 讨论(0)
提交回复
热议问题