The Wayback Machine - https://web.archive.org/web/20240528084944/https://www.geeksforgeeks.org/methods-to-convert-xlsx-format-files-to-csv-on-linux-cli/
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


Similar Reads

DriveSync Local Files with Google Drive using Linux CLI
In this article, We will see how-to DriveSync local files with Google Drive from Linux CLI. Google Drive is widely used for cloud storage. It allows us to access, upload, or download the documents or files inside our drive from any location or device, provided proper authentication. DriveSync is a command-line interface(CLI) tool that synchronizes
3 min read
How to Test Internet on Linux Using speedtest-cli?
While troubleshooting your system for slow internet access, the best way to figure is to measure the internet speed first. To check Internet speed on Linux we will be using third party tool speedtest_cli. It is a simple command-line client based on python for measuring internet bandwidth using speedtest.net infrastructure. Test Download/Upload spee
1 min read
SourceWolf – A CLI Web Crawler Tool in Linux
Web crawling is the process of indexing data on web pages by using a program or automated script and these automated scripts or programs are known by multiple names, that includes web crawler, spider, spider bot, and often shortened to the crawler. Manual crawling consumes a lot of time if the scope of the target is more. SourceWolf is an automated
6 min read
How to check TLS/SSL certificate expiration date from Linux CLI?
Transport Layer Security is referred to as TLS. The system known as Transport Layer Security creates an encrypted session between two computers using the Internet. It authenticates the server's identity and inhibits data interception by hackers. When using the HTTPS protocol, users can securely transfer sensitive data thanks to TLS (and SSL's forer
3 min read
How To Install Telegram-Cli On Linux?
Telegram-CLI is a third-party command-line interface customer for the popular Telegram messaging platform. This allows users to interact with Telegram's services via a terminal or press window. It offers core Telegram features, similar to transferring dispatches, and media, and managing connections and groups. One of its name features is its custom
4 min read
How to switch between the CLI and GUI on a Linux server
The command line interface (CLI) is the text-based way to interact with Linux using keyboard commands. The graphical user interface (GUI) provides a visual desktop with icons and graphics to manage the system. Linux allows smooth transitioning between CLI and GUI. You can access the keyboard-driven terminal or the graphical desktop on the same Linu
4 min read
Ranger - A CLI File Manager
Ranger is a command Line-based file manager with VI key bindings for Linux. It provides almost all features of the GUI file manager into the terminal. It provides a minimalist and nice curses interface with a view of the directory hierarchy. File launcher of ranger is very good that automatically finding out which program to use for what file type.
2 min read
Connecting To Bluetooth Devices Via CLI
The Bluetooth wireless technology is a worldwide specification for a small-form-factor, low-cost radio solution that provides links between mobile computers, mobile phones, and other portable handheld devices. You'll find Bluetooth connectivity in smartphones, smartwatches, wireless earphones, etc. In this article, we'll be learning how to connect
4 min read
Encrypting and Decrypting the Files Using GnuPG in Linux
GnuPG is an encryption module that uses OpenPGP at its core. PGP stands for Pretty Good Privacy. It is an encryption program that provides authentication and cryptographic privacy for data communication. In the age where data is the new oil, the modern age thieves won't intrude in through doors, windows or roofs, but instead, via wires and electric
3 min read
Encrypting Files Using vim editor in Linux
Vim, the popular text editor comes with a built-in feature to encrypt files with a password. Vim uses algorithms like Blowfish to encrypt files. It is faster and convenient than some other utilities available to do so. To get started, all you need is a system with a full version of vim installed. Some Linux distributions are shipped with a minimal
3 min read
Article Tags :