XLS Format (Excel 97-2003)
Description
XLS is the binary file format used by Microsoft Excel versions 97-2003. It's a proprietary format for storing spreadsheet data including formulas, formatting, and multiple sheets.
File Extensions
.xls- Excel 97-2003 files
Implementation Details
Reading
The XLS implementation:
- Uses
xlrdlibrary for reading - Supports multiple sheets (pages)
- Extracts column headers from first row (if not specified)
- Handles dates and numbers appropriately
- Converts each row to a dictionary
Writing
Writing is not currently supported for XLS format. Use XLSX format for writing.
Key Features
- Multiple sheets: Can read from specific sheet by index
- Header detection: Automatically extracts headers from first row
- Date handling: Properly converts Excel dates
- Type handling: Converts numbers and dates appropriately
- Totals support: Can count total rows
Usage
from iterable import open_iterable
# Basic reading (first sheet, headers from first row)
source = open_iterable('data.xls')
for row in source:
print(row)
source.close()
# Read specific sheet
source = open_iterable('data.xls', iterableargs={
'page': 1 # Second sheet (0-indexed)
})
# List available sheets
from iterable.datatypes.xls import XLSIterable
# Discover sheets before opening
sheets = XLSIterable('data.xls').list_tables('data.xls')
print(f"Available sheets: {sheets}")
# List sheets after opening (reuses workbook)
source = open_iterable('data.xls', iterableargs={'page': 0})
all_sheets = source.list_tables() # Reuses open workbook
print(f"All sheets: {all_sheets}")
source.close()
# Specify column names manually
source = open_iterable('data.xls', iterableargs={
'keys': ['id', 'name', 'date'],
'start_line': 0 # Start from first row
})
Parameters
page(int): Sheet index to read (default:0)keys(list[str]): Column names (default: extracted from first row)start_line(int): Row to start reading from (default:0)
Limitations
- Read-only: XLS format does not support writing (use XLSX)
- xlrd dependency: Requires
xlrdpackage - Legacy format: Older Excel format (use XLSX for new files)
- Flat data only: Only supports tabular data
- Limited features: Some Excel features may not be fully supported
- File path required: Requires filename, not stream
Compression Support
XLS files can be compressed with all supported codecs:
- GZip (
.xls.gz) - BZip2 (
.xls.bz2) - LZMA (
.xls.xz) - LZ4 (
.xls.lz4) - ZIP (
.xls.zip) - Brotli (
.xls.br) - ZStandard (
.xls.zst)
Use Cases
- Legacy data: Reading old Excel files
- Data migration: Converting from Excel to other formats
- Data analysis: Processing Excel data
- Reporting: Reading Excel reports