Era Host hosting
EraHost – Free Domain, Cheap Hosting!
Client Area
Support 24/7
Menu

What is SimpleXLSX? A Lightweight PHP Excel Reader

4 min read
15.12.2025

SimpleXLSX is a lightweight PHP library used to read Excel .xlsx files. It is a convenient alternative for working with Excel files when you need to extract data but do not require complex features offered by more heavyweight libraries like PHPExcel or PhpSpreadsheet.

SimpleXLSX PHP Excel Reader
SimpleXLSX — single-file PHP class; PhpSpreadsheet for heavy work.

For related PHP-library / encoding / data-import topics, see mb_detect_encoding in PHP — Detect Character Encoding, PHP ZipArchive::close() Permission Denied, and vqmod::bootup — PHP domdocument Extension.

The class file, simplexlsx.class.php, provides an easy way to parse Excel spreadsheets in PHP without requiring additional extensions beyond the built-in PHP functionality.

Features of SimpleXLSX

Read .xlsx Files

Parse and retrieve data from Excel .xlsx files. Does not support the older .xls format.

Lightweight and Easy to Use

No need to install additional dependencies. Small file size and minimal performance overhead.

Compatibility

Works with most modern PHP versions.

Linux VDS
High performance for your projects
  • Root access and flexible setup
  • Control panel
  • NVMe disks
  • DDR5
Linux VDS

How to Use simplexlsx.class.php

Download the Library

Include the File in Your Project

Save simplexlsx.class.php in your project directory and include it in your script:

require_once 'simplexlsx.class.php';

Read an Excel File

Use the SimpleXLSX class to load and parse an .xlsx file.

Example:

<?php

require_once 'simplexlsx.class.php';



if ($xlsx = SimpleXLSX::parse('example.xlsx')) {

    // Print rows from the first sheet

    foreach ($xlsx->rows() as $row) {

        print_r($row);

    }

} else {

    // Handle error

    echo SimpleXLSX::parseError();

}

?>

Key Methods in SimpleXLSX

Method Description
parse($filename) Loads the .xlsx file. Returns an object on success or false on failure.
rows() Returns all rows from the first sheet as an array.
rowsEx() Returns rows with additional cell information (e.g., data type).
sheetNames() Returns an array of sheet names.
dimension() Returns the dimensions of the sheet ([rows, cols]).
parseError() Returns the last error message, if any.

Advanced Example: Handling Multiple Sheets

If your Excel file contains multiple sheets, you can loop through them.

<?php

require_once 'simplexlsx.class.php';



if ($xlsx = SimpleXLSX::parse('example.xlsx')) {

    foreach ($xlsx->sheetNames() as $sheetIndex => $sheetName) {

        echo "Sheet: $sheetName\n";

        

        foreach ($xlsx->rows($sheetIndex) as $row) {

            print_r($row);

        }

    }

} else {

    echo SimpleXLSX::parseError();

}

?>

Error Handling

To handle errors, use the parseError() method. It will provide helpful error messages if the file is invalid or unreadable.

Example:

<?php

require_once 'simplexlsx.class.php';



if (!$xlsx = SimpleXLSX::parse('invalid_file.xlsx')) {

    echo 'Error: ' . SimpleXLSX::parseError();

}

?>

Advantages and Limitations

Advantages

  1. Ease of Use: Minimal setup and simple syntax.
  2. Performance: Lightweight and faster for simple Excel file parsing compared to alternatives.
  3. No External Dependencies: Works with native PHP functionality.

Limitations

  1. Read-Only: Can only read .xlsx files; it cannot write or modify them.
  2. Limited Features: Does not support advanced Excel features like charts, macros, or complex formatting.
  3. No .xls Support: Only works with .xlsx files (Office Open XML format).

Alternatives to SimpleXLSX

If your project requires more advanced Excel handling capabilities, consider:

  1. PhpSpreadsheet:
    • Supports reading and writing .xls and .xlsx files.
    • Offers advanced features like formatting, charts, and formulas.
    • PhpSpreadsheet GitHub
  2. PHPExcel (Deprecated):

simplexlsx.class.php is an excellent choice for lightweight and straightforward Excel file parsing in PHP. It is ideal for projects requiring basic data extraction without heavy dependencies. For advanced use cases, PhpSpreadsheet might be a better fit.

Frequently asked questions
SimpleXLSX: read-only, single-file, no deps — fits shared hosting where Composer isn't an option. Limited to .xlsx reading. PhpSpreadsheet: read + write, .xlsx/.xls/.ods/CSV, many features, Composer dep, slower. For occasional Excel reads on shared hosting: SimpleXLSX. For full Excel-app: PhpSpreadsheet.
SimpleXLSX loads the whole file into memory. 100MB xlsx with 500k rows: expect 500MB+ RAM usage. memory_limit must accommodate. For very large files (millions of rows), PhpSpreadsheet's streaming reader handles better. SimpleXLSX is fine for typical business spreadsheets.
`$xlsx = SimpleXLSX::parse('file.xlsx');` loads everything. Iterate via `$xlsx->sheets[$idx]` or `$xlsx->rows($idx)`. Sheet names: `$xlsx->sheetNames()`. Selective load to save memory: SimpleXLSX doesn't optimize for this — PhpSpreadsheet has more granular control.
Partly. Excel stores dates as numbers (days since 1900). SimpleXLSX exposes raw numbers; you handle conversion. Use `gmdate('Y-m-d', ($value - 25569) * 86400)` for Unix timestamp conversion. PhpSpreadsheet has built-in date conversion helpers. For date-heavy files, PhpSpreadsheet less error-prone.
Related articles
Set Encoding for Dynamic Content with charset=windows-1251
MySQL error in file: /engine/classes/mysql.php at line 61
Debugging session_start() Errors in PHP Using Error Logs