Overview
PhpSpreadsheet provides a comprehensive set of readers for loading various spreadsheet file formats. All readers implement theIReader interface and extend the BaseReader class, providing a consistent API for loading spreadsheet data.
Supported Formats
PhpSpreadsheet includes readers for the following formats:- Xlsx - Excel 2007+ (.xlsx) files
- Xls - Excel 97-2003 (.xls) files
- Ods - OpenDocument Spreadsheet (.ods) files
- Csv - Comma-separated values (.csv) files
- Html - HTML table files
- Slk - SYLK (Symbolic Link) files
- Gnumeric - Gnumeric spreadsheet files
- Xml - Excel 2003 XML files
IReader Interface
All readers implement theIReader interface located at PhpOffice\PhpSpreadsheet\Reader\IReader.
Core Methods
load()
Loads a spreadsheet from a file.The path to the file to load
Optional flags to control loading behavior:
IReader::LOAD_WITH_CHARTS- Load any charts defined in the fileIReader::READ_DATA_ONLY- Read only data, not formattingIReader::IGNORE_EMPTY_CELLS- Don’t read empty cellsIReader::IGNORE_ROWS_WITH_NO_CELLS- Don’t load rows with no cellsIReader::ALLOW_EXTERNAL_IMAGES- Allow loading external images (use with caution)IReader::DONT_ALLOW_EXTERNAL_IMAGES- Prevent loading external imagesIReader::CREATE_BLANK_SHEET_IF_NONE_READ- Create blank sheet if no sheets are read
canRead()
Checks if the reader can read a specific file.The path to the file to check
Configuration Methods
setReadDataOnly()
Configures the reader to read only cell data values, ignoring formatting.Set to
true to read only data values, false (default) to read data and formattingsetReadEmptyCells()
Configures whether to read empty cells.Set to
true (default) to read all cells, false to ignore empty cellssetIncludeCharts()
Configures whether to load charts from the file.Set to
true to load charts, false (default) to ignore chartssetLoadSheetsOnly()
Specifies which worksheets to load.Array of worksheet names to load, a single worksheet name string, or
null to load all worksheetssetReadFilter()
Sets a read filter to selectively load cells.An object implementing the IReadFilter interface
BaseReader Class
TheBaseReader abstract class (PhpOffice\PhpSpreadsheet\Reader\BaseReader) provides the common implementation for all readers.
Additional Methods
listWorksheetInfo()
Returns information about worksheets without loading the entire file.worksheetName- Name of the worksheetlastColumnLetter- Last column letterlastColumnIndex- Last column indextotalRows- Total number of rowstotalColumns- Total number of columnssheetState- Sheet visibility state
listWorksheetNames()
Returns worksheet names without loading the entire file.setValueBinder()
Sets a custom value binder for cell values.IReadFilter Interface
TheIReadFilter interface allows you to selectively load cells from a spreadsheet, which is useful for reading large files efficiently.
Example: Custom Read Filter
Common Usage Patterns
Basic File Loading
Using IOFactory
The IOFactory can automatically detect the file format:Reading Data Only (No Formatting)
Loading Specific Worksheets
Using Flags
Getting Worksheet Information
Using Read Filters for Large Files
Security Considerations
External Images
Be cautious when usingALLOW_EXTERNAL_IMAGES flag or setAllowExternalImages(true), as this can expose your application to security risks if the spreadsheet contains malicious URLs.
XML Security
All XML-based readers (Xlsx, Ods, Xml, Html) use theXmlScanner security scanner to protect against XML External Entity (XXE) attacks.
Performance Tips
- Use
setReadDataOnly(true)if you don’t need formatting information - Use
setReadEmptyCells(false)orIGNORE_EMPTY_CELLSflag to skip empty cells - Use read filters to load only the data you need from large files
- Use
setLoadSheetsOnly()to load specific worksheets - Consider chunked reading for very large files using read filters

