Convert Xlsx to CSV in Linux With Command Line

How to convert xlsx file to csv file using shell script?

sudo pip install xlsx2csv

You can refer to
https://github.com/dilshod/xlsx2csv

Convert xlsx to text CSV via command line only on Linux

Here is the command:

localc --headless  --convert-to csv:"Text - txt - csv (StarCalc)" *.xlsx

The above will save all converted files in current directory(directory from where you'll run the command). All converted files will have their filename extensions changed to csv.

Alternative, method is the use of unoconv which i've not used.

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

shell script to convert .xls to .csv and then delete the .xls files that are converted?

You can edit this line:

for i in /reports/cctv_xls/*.xls; do libreoffice --headless --convert-to csv "$i" --outdir /cctv_reports/cctv_csv/; done

to be

for i in /reports/cctv_xls/*.xls; do libreoffice --headless --convert-to csv "$i" --outdir /cctv_reports/cctv_csv/ && rm $i; done

this will delete the xls file only if its successfully converted to csv



Related Topics



Leave a reply



Submit