In daily work, we often need to process and convert Excel files in different formats to suit different needs and software compatibility. The two common formats of Excel files are XLS (Excel 97-2003) and XLSX (Excel 2007 and above). This article will explain in detail how to convert between XLS and XLSX formats using Python.
Python library installation
Required Python library - for Python. This Python library supports a variety of programming operations for Excel documents, including creation, reading, editing, conversion, etc. You can download the product package through this link and then install it from the local path. You can also directly use the following pip command to install it:
pip install
XLS format and XLSX format are converted
XLSX format has become the preferred format for modern Excel file processing due to its XML-based structure, more powerful functional support and security. The XLS format still has its own specific application scenarios due to its compatibility in older versions of Excel and the use of specific features.
To use Python to achieve flexible conversion in both formats, refer to the following steps:
- Create a Workbook workbook object;
- Use the LoadFromFile() method to load .xls or .xlsx files;
- Use the SaveToFile(fileName, version) method to implement the conversion.
Python convert XLSX to XLS
from import * from import * # Load XLSX fileworkbook = Workbook() ("Example.xlsx") # Save XLSX file as XLS format("Xlsx to", ExcelVersion.Version97to2003) ()
Python converts XLS to XLSX
from import * from import * # Load XLS fileworkbook = Workbook() ("Example.xls") # Save XLS file as XLSX format("Xls to", ExcelVersion.Version2016) ()
For Python also supports converting Excel (.xls/.xlsx) files to PDF, pictures, HTML and other file formats. Tutorial examples:
/spirexls/
This is the end of this article about Python's implementation of the mutual conversion of Excel XLS and XLSX formats. For more related content to convert Python Excel XLS and XLSX formats, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!