Location>code7788 >text

Python Excel XLS and XLSX format conversion each other

Popularity:625 ℃/2024-10-14 17:03:45

In our 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 for Excel files are XLS (Excel 97-2003) and XLSX (Excel 2007 and above). This article will detail how to use Python to convert between XLS and XLSX formats.

Python library installation

Required Python Library - for Python.This Python library supports a wide range of programmatic operations on Excel documents, including creating, reading, editing, converting, and more. You can download the product package from this link and install it from your local path, or you can install it directly using the pip command below:

pip install

 

XLS format and XLSX format interconversion

The XLSX format has become the format of choice for modern Excel file handling due to its XML-based structure, more robust feature support and security. The XLS format, on the other hand, still has its 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 between these two format pieces, refer to the following steps:

  1. Creates a Workbook object;
  2. Use the LoadFromFile() method to load .xls or .xlsx files;
  3. Use the SaveToFile(fileName, version) method to do the conversion.

 

Python Convert XLSX to XLS

from  import *
from  import *
 
# Loading XLSX files
workbook = Workbook()
("Example.xlsx")
 
# Save XLSX File as XLS Format
("Xlsx to", ExcelVersion.Version97to2003)
()

 

Python Convert XLS to XLSX

from  import *
from  import *
 
# Loading XLS files
workbook = Workbook()
("Example.xls")
 
# Save XLS file as XLSX format
("Xls to", ExcelVersion.Version2016)
()

 


for Python also supports converting Excel (.xls/ .xlsx) files to PDF, images, HTML and many other file formats, tutorial examples:

/spirexls/