Convert XLS to CSV on command line Convert XLS to CSV on command line windows windows

Convert XLS to CSV on command line


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.QuitEnd IfDim oExcelSet oExcel = CreateObject("Excel.Application")Dim oBookSet oBook = oExcel.Workbooks.Open(Wscript.Arguments.Item(0))oBook.SaveAs WScript.Arguments.Item(1), 6oBook.Close FalseoExcel.QuitWScript.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.


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 <xls/xlsx source file> <csv destination file>"    Wscript.QuitEnd Ifcsv_format = 6Set objFSO = CreateObject("Scripting.FileSystemObject")src_file = objFSO.GetAbsolutePathName(Wscript.Arguments.Item(0))dest_file = objFSO.GetAbsolutePathName(WScript.Arguments.Item(1))Dim oExcelSet oExcel = CreateObject("Excel.Application")Dim oBookSet oBook = oExcel.Workbooks.Open(src_file)oBook.SaveAs dest_file, csv_formatoBook.Close FalseoExcel.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.


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