Open In App

Methods to Convert xlsx Format Files to CSV on Linux CLI

Last Updated : 11 May, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

XLSX is a format/file extension for Open XML Spreadsheet file format used by Microsoft Excel. Transforming xlsx to csv (comma-separated file) is easy via command line. Here are few methods to convert xlsx to csv format.

Gnumeric Spreadsheet Program

It is a GNOME-based program, a spreadsheet application that replicates basic features of a popular commercial program like Excel. It can import and export data to and from multiple formats like including CSV, Microsoft Excel, HTML, OpenDocument, Quattro Pro, and LaTeX.  

To install Gnumeric in Linux use the apt-get command to install the Gnumeric repository via Linux terminal.

$ sudo apt-get install gnumeric

Methods to Convert xlsx Format Files to CSV on Linux CLI

Now to convert xlsx format to csv format using ssconvert command of Gnumeric to convert the file. 

$ ssconvert --export-type=Gnumeric_stf:stf_csv SampleData.xlsx convert.csv

To view the contents of the file using the cat command to check the csv file.

Methods to Convert xlsx Format Files to CSV on Linux CLI

xlsx2csc converter

A python application to convert XLSX/XLS files to CSV format. There is also an option to convert a specific sheet or all the sheets from the data. xlsx2csv has a feature to export all sheets at once. 

To install xlsx2csv python should be installed in the Linux machine.

pip install xlsx2csv

Or we can install it in Linux terminal with the help of apt-get command as Kali Linux has the package is pre-installed,

$ sudo apt install xlsx2csv

Methods to Convert xlsx Format Files to CSV on Linux CLI

Now convert the file from xlsx to csv and view the contents:

xlsx2csv file_name.xlsx > New_file.csv

Methods to Convert xlsx Format Files to CSV on Linux CLI

Here we see that xlsx2cv has only converted a single sheet, but our sheet has multiple sheets so to convert all of them to csv, the xlsx2csv converter has many parameters to convert the files/sheets.

  • -a, –all – export all sheets
  • -d – DELIMITER for columns delimiter in csv
  • -p – SHEETDELIMITER for sheet delimiter used to separate sheets, pass
  • -s – SHEETID for the sheet number to convert
$ xlsx2csv SampleData.xlsx --all > Output.csv

To convert all the sheets from the file, execute the following command, on viewing the contents of the file we see that there are 4 sheets (sheet 1: Instructions, sheet 2: sales order, sheet 3: Sample number, and sheet 4: my link) being converted from xlsx to csv format

Methods to Convert xlsx Format Files to CSV on Linux CLI

csvkit Tool

The tool is a python library for working with csv files with this we can manipulate, organize and analyze data. To use the tool in2csv is executed for converting files. The tool is light and user-friendly. Install the csvkit tool from Linux CLI using the command given below,

$ sudo apt install csvkit

Methods to Convert xlsx Format Files to CSV on Linux CLI

Convert the xlsx file to csv by executing the following command:

$ in2csv SampleData.xlsx > sample.csv

Methods to Convert xlsx Format Files to CSV on Linux CLI

Viewing contents of the file using cat command:

$ cat sample.csv

Methods to Convert xlsx Format Files to CSV on Linux CLI

unoconv

A command-line program to convert office document file format. It also uses LibreOffice to do the conversion, where it can import to any file format that LibreOffice is capable of exporting. For installation in Linux machine use the following the command,

$ sudo apt install unoconv

Converting the Microsoft Excel file to csv format we execute or run the command given below, this command is capable to convert many files format. This also means that it indicates desired format we want to convert the file to, to mention the output format the following parameters are used.

$ unoconv -f csv -o data.csv SampleData.xlsx

unoconv options:

  • -f, –format=format: Specify the output format
  • -o, –output=name: Output basename, filename or directory

View contents or to check if the output file has successfully converted the file, we use the cat command

$ cat data.csv

LibreOffice Headless

A package allowing LibreOffice to work in command-line with the help of a headless flag allows the application to work without a user interface. It works by converting a single or group of files from one format to another. We can directly use it from CLI, installation of LibreOffice is not required. Indicate the output file format (csv) that you would desire to get with –convert-to parameter followed by file for conversion as done below. After this use ls command to check the output file of xlsx format

$ libreoffice --headless --convert-to csv --outdir conv/ SampleData.xlsx

Use cat command to view contents of the file:

$ cat conv/SampleData.csv


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads