Convert Between Excel XLS and XLSX Format in Python

Andrew Wilson
2 min readOct 15, 2024

--

XLS is the default file format used in Excel 2003 and earlier versions. XLSX is a new file format standard introduced in versions after Excel 2007 and is based on the Open XML international standard. XLSX files are typically smaller and support larger amounts of data than the XLS format. Based on the requirements of different applications, it may sometimes be necessary to convert between XLS and XLSX formats. In this article, we will share how to convert XLS to XLSX, or convert XLSX to XLS through Python.

Python Excel Converter Library

Spire.XLS for Python is a Python library supports various Excel document processing features. It can be directly installed to your system using the pip command below

pip install Spire.XLS

Or you can download the product package via below link and then installing it from a local path.

Python — Conversion Between XLS Format and XLSX Format

The XLSX format has become the format of choice for modern Excel files due to its XML-based structure, stronger feature support and security. XLS format, on the other hand, still has its specific application scenarios due to its compatibility with older versions of Excel.

To convert between these two formats using Python, refer to the following steps:

  1. Create a Workbook object;
  2. Load .xls or .xlsx files using the LoadFromFile() method;
  3. Call the SaveToFile(fileName, version) method to realize the conversion.

Convert XLSX to XLS in Python

from spire.xls import *
from spire.xls.common import *

# Load a XLSX file
workbook = Workbook()
workbook.LoadFromFile("sample.xlsx")

# Save the XLSX file in XLS format
workbook.SaveToFile("XlsxToXls.xls", ExcelVersion.Version97to2003)
workbook.Dispose()

Convert XLS to XLSX in Python

from spire.xls import *
from spire.xls.common import *

# Load a XLS file
workbook = Workbook()
workbook.LoadFromFile("sample.xls")

# Save the XLS file in XLSX format
workbook.SaveToFile("XlsToXlsx.xlsx", ExcelVersion.Version2016)
workbook.Dispose()

Spire.XLS for Python also supports converting Excel (.xls/ .xlsx) files to PDF, images, HTML and many other file formats. Check below for more demos:

--

--

Andrew Wilson
Andrew Wilson

Written by Andrew Wilson

Explore C#, Java and Python solutions for processing Word/Excel/PowerPoint/PDF files.

No responses yet