Cyberithub

How to convert XLSX file to XLS or CSV file in Linux

Advertisements

In this article, I will take you through the steps to convert xlsx file to xls or csv file in Linux. Many times you might face a scenario where you have to read the data from the latest excel file in Linux but you cannot do it until you convert it to csv file.

Also there might be a scenario where you need to convert the latest excel file i.e xlsx file to the older excel format i.e xls file as you might not able to work with xlsx file directly. For all these scenarios we have few important tools available that can be employed to serve the purpose. We will discuss about those tools in below section with the help of examples.

Advertisements

 

How to convert XLSX file to XLS or CSV file in Linux

How to convert XLSX file to XLS or CSV file in Linux

Also Read: How to Install MySQL on Ubuntu 20.04 LTS (Focal Fossa)

Step 1: Prerequisites

a) You should have a running Linux Server.

Advertisements

b) You should have sudo or root access to run privileged commands.

c) You should have xls2csv utility available in your System. You can check How to Install xls2csv on Ubuntu 20.04 LTS (Focal Fossa) to install the utility.

Advertisements

 

Step 2: Install Gnumeric 

Gnumeric is a free and very powerful open source spreadsheet program available in Linux that can be employed to convert xlsx file to xls. To install this tool in a Ubuntu/Debian based systems, you just need to use sudo apt-get install gnumeric command as shown below.

cyberithub@ubuntu:~$ sudo apt-get install gnumeric
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libfwupdplugin1 libllvm11 libxmlb1
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
gnumeric-common gnumeric-doc gsfonts libgoffice-0.10-10 libgoffice-0.10-10-common pxlib1
Suggested packages:
gnumeric-plugins-extra libgsf-1-dev docbook-xsl
The following NEW packages will be installed:
gnumeric gnumeric-common gnumeric-doc gsfonts libgoffice-0.10-10 libgoffice-0.10-10-common pxlib1
0 upgraded, 7 newly installed, 0 to remove and 24 not upgraded.
Need to get 20.8 MB of archives.
After this operation, 69.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://in.archive.ubuntu.com/ubuntu focal/universe amd64 gnumeric-common all 1.12.46-1ubuntu2 [2,665 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu focal/universe amd64 libgoffice-0.10-10-common all 0.10.46-1 [679 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu focal/universe amd64 libgoffice-0.10-10 amd64 0.10.46-1 [1,557 kB]
Get:4 http://in.archive.ubuntu.com/ubuntu focal/universe amd64 pxlib1 amd64 0.6.8-1 [36.8 kB]
Get:5 http://in.archive.ubuntu.com/ubuntu focal/universe amd64 gsfonts all 1:8.11+urwcyr1.0.7~pre44-4.4 [3,120 kB]
Get:6 http://in.archive.ubuntu.com/ubuntu focal/universe amd64 gnumeric amd64 1.12.46-1ubuntu2 [2,319 kB]
Get:7 http://in.archive.ubuntu.com/ubuntu focal/universe amd64 gnumeric-doc all 1.12.46-1ubuntu2 [10.4 MB]
Fetched 20.8 MB in 7s (3,051 kB/s)
Preconfiguring packages ...
Selecting previously unselected package gnumeric-common.
(Reading database ... 182730 files and directories currently installed.)
Preparing to unpack .../0-gnumeric-common_1.12.46-1ubuntu2_all.deb ...
Unpacking gnumeric-common (1.12.46-1ubuntu2) ...
Selecting previously unselected package libgoffice-0.10-10-common.
Preparing to unpack .../1-libgoffice-0.10-10-common_0.10.46-1_all.deb ...
Unpacking libgoffice-0.10-10-common (0.10.46-1) ...
Selecting previously unselected package libgoffice-0.10-10.
Preparing to unpack .../2-libgoffice-0.10-10_0.10.46-1_amd64.deb ...
Unpacking libgoffice-0.10-10 (0.10.46-1) ...
Selecting previously unselected package pxlib1.
Preparing to unpack .../3-pxlib1_0.6.8-1_amd64.deb ...
Unpacking pxlib1 (0.6.8-1) ...
Selecting previously unselected package gsfonts.
Preparing to unpack .../4-gsfonts_1%3a8.11+urwcyr1.0.7~pre44-4.4_all.deb ...
Unpacking gsfonts (1:8.11+urwcyr1.0.7~pre44-4.4) ...
Selecting previously unselected package gnumeric.
Preparing to unpack .../5-gnumeric_1.12.46-1ubuntu2_amd64.deb ...
Unpacking gnumeric (1.12.46-1ubuntu2) ...
Selecting previously unselected package gnumeric-doc.
Preparing to unpack .../6-gnumeric-doc_1.12.46-1ubuntu2_all.deb ...
Unpacking gnumeric-doc (1.12.46-1ubuntu2) ...
Setting up gnumeric-common (1.12.46-1ubuntu2) ...
Setting up pxlib1 (0.6.8-1) ...
Setting up gnumeric-doc (1.12.46-1ubuntu2) ...
Setting up gsfonts (1:8.11+urwcyr1.0.7~pre44-4.4) ...
Setting up libgoffice-0.10-10-common (0.10.46-1) ...
Setting up libgoffice-0.10-10 (0.10.46-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for fontconfig (2.13.1-2ubuntu3) ...
Processing triggers for desktop-file-utils (0.24-1ubuntu3) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu1) ...
Processing triggers for libglib2.0-0:amd64 (2.64.6-1~ubuntu20.04.4) ...
Setting up gnumeric (1.12.46-1ubuntu2) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...

 

Step 3: Convert XLSX file to XLS file 

ssconvert is one utility you will get after installing Gnumeric package in your System. To convert latest excel file format xlsx to the older xls format, you need to use ssconvert --export-type=<ID> <XLSX_FILE> <XLS_FILE> syntax.

Advertisements
cyberithub@ubuntu:~$ ssconvert --export-type=Gnumeric_Excel:excel_dsf excel_example.xlsx excel_example.xls

 

Step 4: Convert XLS file to CSV file

Now if you want to convert XLS file to CSV then you need to use another tool called xls2csv. Here we have a XLS file called excel_example.xls which needs to be converted to excel_example.csv file. For that we are using xls2csv -x excel_example.xls -s cp1252 -d 8859-1 > excel_example.csv command as shown below.

cyberithub@ubuntu:~$ xls2csv -x excel_example.xls -s cp1252 -d 8859-1 > excel_example.csv

-x : print unknown Unicode chars as \xNNNN, rather than as question marks

-s : specifies source charset

-d : specifies destination charset name

After converting the file into CSV format, you can try to check the contents of the file by using cat excel_example.csv command as shown below.

cyberithub@ubuntu:~$ cat excel_example.csv
"Employee ID","Employee Name","Department","Salary in $(per month)"
"1098567","Cassie","Accounts","5200"
"1076345","John","Finance","5200"
"1045667","Mike","Facility","4800"
"1023454","Chris","Engineering","6200"
"1076256","Trevor","Medical ","6300"
"1054864","Ryan","Security","4900"
"Employee ID","Employee Name","Department","Salary in $(per month)"
"1098567","Cassie","Accounts","5200"
"1076345","John","Finance","5200"
"1045667","Mike","Facility","4800"
"1023454","Chris","Engineering","6200"
"1076256","Trevor","Medical ","6300"
"1054864","Ryan","Security","4900"

Leave a Comment