Convert XLS To XLSX In Python

Want to know 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 to xlsx using python, so follow this tutorial till the end.
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 today I will show you how to convert them into xlsx files.
I will show you everything and provide you with the python code to convert xls to xlsx file. So now let’s see it in code.
Code To Convert XLS To XLSX In Python
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 python program to convert xls to xlsx file so now to run this program follow the below steps
To run this python program:
- First, create a new folder for this program.
- Open the folder in a code editor.
- Create a python file with .py extension.
- Copy the code and paste it in the file.
Now you have the code, As you can see I have used a python library called xls2xlsx to convert xls file to xlsx in python so first 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.
If you don’t have a xls file, you can download from this website: Download XLS Sample File for testing this program move the file to the root of this program folder.
Now you are ready to run this program, To run it open a command prompt at the program folder and run the below command.
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. As you can see, we successfully converted xls file to xlsx file in python.
Summary
This was the python program to convert xls to xlsx file. I hope you found this tutorial helpful and useful. Do share this program with your friends who might find it helpful.
Here are some more python programs for you:
- Convert Generator to list in python.
- Convert Ipynb to Py file in python.
- Convert wav to mp3 in python.
- Convert miles to feet in python.
- Convert KG to Pounds in python.
I hope you found what you were looking for from this tutorial and if you want more tutorials like this in the future, do join our Telegram channel for updates.
Thanks for reading, have a nice day 🙂