Pythondex
Python Conversion Programs

Convert XLS To XLSX In Python

Last updated January 31, 2024 by Jarvis Silva

Looking for a tutorial on how to convert xls to xlsx in python then you are at the right place today in this tutorial I will show you how to convert xls file to xlsx file format using python

XLS and XLSX are files used by Microsoft Excel for reading and writing excel data, so what’s the difference between them? Well xls was used by excel from 1997 to 2003 after that they used xlsx file format.

So xlsx is like a new version so if you have old Excel files in xls version then you might need to convert them to xlsx format which we will see in this tutorial.

Python Code To Convert XLS To XLSX


from xls2xlsx import XLS2XLSX

# Enter the xls file name here
x2x = XLS2XLSX("sample.xls")

# Enter the xlsx file name you want after converting here
x2x.to_xlsx("output.xlsx")

Above is the three lines of python code to convert xls to xlsx it is because I have used a python library called xls2xlsx, which allows us to convert xls file to xlsx file format in python so you need to install it, to install run the below command.

 
pip install xls2xlsx

It will install the library now you are ready to run this program. Before that, you need to enter the path of the xls file you want to convert in the first line and also give a name to the xlsx file you want in the second line.

Now you are ready to run this program, To run it open a command prompt at the program folder and run the below command or else you can use an online python compiler.


python filename.py

The above command will run the program and you will see a new file created with the extension xlsx you can open it using Excel, this was for this tutorial I hope you found this tutorial helpful and useful, do share this program with your friends who might need it.

Here are some more python programs for you:

I hope you found what you were looking for from this tutorial and if you want more tutorials and resources like this in the future, do join our Telegram channel for updates.

Thanks for reading, have a nice day 🙂