Xls writer exports spreadsheets to Excel 97-2003 format (.xls), also known as BIFF (Binary Interchange File Format).
Namespace: PhpOffice\PhpSpreadsheet\Writer\Xls
Extends: BaseWriter
Class Overview
The Xls writer creates binary files in the Excel 5.0/95 and Excel 97-2003 formats. This format uses the BIFF structure within an OLE (Object Linking and Embedding) container.The Xls format has limitations compared to newer formats. Consider using Xlsx for new projects unless backward compatibility is required.
Constructor
The spreadsheet object to write
Key Methods
save()
File path or resource to write to
Optional flags (see IWriter constants)
Usage Examples
Basic Export
Disable Formula Calculation
Download to Browser
Write to String
Format Limitations
The Xls format has several limitations compared to Xlsx:Row and Column Limits
- Maximum rows: 65,536 (2^16)
- Maximum columns: 256 (A-IV)
- Maximum cell content: 32,767 characters
Feature Support
The Xls writer supports:- ✅ Multiple worksheets (limited to 255)
- ✅ Cell formatting (fonts, colors, borders, fills)
- ✅ Number formats
- ✅ Formulas (with some limitations)
- ❌ Charts (not supported)
- ✅ Images (JPEG, PNG, BMP - converted to PNG/JPEG)
- ⚠️ Rich text (limited support)
- ✅ Merged cells
- ✅ Data validation
- ⚠️ Conditional formatting (limited)
- ✅ Page setup
- ✅ Headers and footers
- ✅ Document properties
- ✅ Named ranges
- ✅ Autofilters
- ❌ Tables (not supported)
- ✅ Comments
- ✅ Hyperlinks
Image Handling
Technical Details
File Structure
The Xls file format consists of:- OLE Container - Provides compound file structure
- Workbook Stream - Contains global workbook data
- Worksheet Streams - One per worksheet
- Summary Information - Document metadata
- Document Summary Information - Extended properties
String Table
The writer maintains a shared string table to optimize storage:Color Mapping
The Xls format uses an indexed color palette. PhpSpreadsheet automatically maps RGB colors to the nearest palette color:When to Use Xls
Use the Xls writer when:- ✅ Compatibility with Excel 97-2003 is required
- ✅ Users have older versions of Excel
- ✅ File format is mandated by legacy systems
- ✅ Your data fits within the format’s limitations
- ❌ You need more than 65,536 rows
- ❌ You need more than 256 columns
- ❌ You need charts
- ❌ You need advanced conditional formatting
- ❌ File size is a concern (Xlsx is typically smaller)
Related
- Xlsx Writer - Modern Excel format
- Ods Writer - OpenDocument format
- Writers Overview - Common writer patterns

