Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert XLS to CSV on command line

Tags:

windows

csv

excel

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's not possible using Microsoft Office.

like image 490
Joel Avatar asked Dec 07 '09 06:12

Joel


People also ask

How do you convert XLS to CSV in Linux?

To install Gnumeric in Linux use the apt-get command to install the Gnumeric repository via Linux terminal. Now to convert xlsx format to csv format using ssconvert command of Gnumeric to convert the file. To view the contents of the file using the cat command to check the csv file.


2 Answers

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.

like image 53
ScottF Avatar answered Oct 07 '22 11:10

ScottF


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.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.

like image 45
plang Avatar answered Oct 07 '22 13:10

plang