PHPackages                             shuchkin/simplexlsx - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. shuchkin/simplexlsx

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

shuchkin/simplexlsx
===================

Parse and retrieve data from Excel XLSx files. MS Excel 2007 workbooks PHP reader.

1.1.16(5mo ago)1.8k3.8M—2.3%492[4 issues](https://github.com/shuchkin/simplexlsx/issues)16MITPHPPHP &gt;=5.5

Since Mar 6Pushed 5mo ago41 watchersCompare

[ Source](https://github.com/shuchkin/simplexlsx)[ Packagist](https://packagist.org/packages/shuchkin/simplexlsx)[ Docs](https://github.com/shuchkin/simplexlsx)[ RSS](/packages/shuchkin-simplexlsx/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (46)Used By (16)Security (2)

SimpleXLSX class (Official)
===========================

[](#simplexlsx-class-official)

[![](https://camo.githubusercontent.com/dad7e16a7432fc2f1568c1cc4cf681474bcdfd2a04cc0f473f419b63a66c6787/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73687563686b696e2f73696d706c65786c7378)](https://packagist.org/packages/shuchkin/simplexlsx)[![](https://camo.githubusercontent.com/a90215a61fae996f02f5591cf7c4b3f348638bfabe9c5f7f89c7de27d603201c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f73687563686b696e2f73696d706c65786c7378)](https://github.com/shuchkin/simplexlsx/blob/master/license.md) [![](https://camo.githubusercontent.com/3e87cbf576d4329e71b9251c06048d73dab67c12beb3a9556de6b74c3c8782e4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f73687563686b696e2f73696d706c65786c7378)](https://github.com/shuchkin/simplexlsx/stargazers) [![](https://camo.githubusercontent.com/98dc2909ca28f0f7c861f5f39a268ae9f5bed0c43a089c898af0d2f43df7ec58/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f73687563686b696e2f73696d706c65786c7378)](https://github.com/shuchkin/simplexlsx/network) [![](https://camo.githubusercontent.com/c8d18864f994eda18633aa1835f64a76fe3925c16011b6c7b83f72419f862c85/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f73687563686b696e2f73696d706c65786c7378)](https://github.com/shuchkin/simplexlsx/issues)[![](https://camo.githubusercontent.com/14840ac5403b9b48a75934a8854b4af0395fc02ca81cba785f59c917da7bd6a9/68747470733a2f2f696d672e736869656c64732e696f2f6f70656e636f6c6c6563746976652f616c6c2f73696d706c65786c7378)](https://opencollective.com/simplexlsx)

Parse and retrieve data from Excel XLSx files. MS Excel 2007 workbooks PHP reader. No addiditional extensions need (internal unzip + standart SimpleXML parser).

See also:
[SimpleXLS](https://github.com/shuchkin/simplexls) old format MS Excel 97 php reader.
[SimpleXLSXGen](https://github.com/shuchkin/simplexlsxgen) xlsx php writer.

*Hey, bro, please ★ the package for my motivation :) and [donate](https://opencollective.com/simplexlsx) for more motivation!*

**Sergey Shuchkin**

Basic Usage
-----------

[](#basic-usage)

```
use Shuchkin\SimpleXLSX;

if ( $xlsx = SimpleXLSX::parse('book.xlsx') ) {
    print_r( $xlsx->rows() );
} else {
    echo SimpleXLSX::parseError();
}
```

```
Array
(
    [0] => Array
        (
            [0] => ISBN
            [1] => title
            [2] => author
            [3] => publisher
            [4] => ctry
        )

    [1] => Array
        (
            [0] => 618260307
            [1] => The Hobbit
            [2] => J. R. R. Tolkien
            [3] => Houghton Mifflin
            [4] => USA
        )

)

```

Installation
------------

[](#installation)

The recommended way to install this library is [through Composer](https://getcomposer.org). [New to Composer?](https://getcomposer.org/doc/00-intro.md)

This will install the latest supported version:

```
$ composer require shuchkin/simplexlsx
```

or download PHP 5.5+ class [here](https://github.com/shuchkin/simplexlsx/blob/master/src/SimpleXLSX.php)

Basic methods
-------------

[](#basic-methods)

```
// open
SimpleXLSX::parse( $filename, $is_data = false, $debug = false ): SimpleXLSX (or false)
SimpleXLSX::parseFile( $filename, $debug = false ): SimpleXLSX (or false)
SimpleXLSX::parseData( $data, $debug = false ): SimpleXLSX (or false)
// simple
$xlsx->rows($worksheetIndex = 0, $limit = 0): array
$xlsx->readRows($worksheetIndex = 0, $limit = 0): Generator - helps read huge xlsx
$xlsx->toHTML($worksheetIndex = 0, $limit = 0): string
// extended
$xlsx->rowsEx($worksheetIndex = 0, $limit = 0): array
$xlsx->readRowsEx($worksheetIndex = 0, $limit = 0): Generator - helps read huge xlsx with styles
$xlsx->toHTMLEx($worksheetIndex = 0, $limit = 0): string
// meta
$xlsx->dimension($worksheetIndex):array [num_cols, num_rows]
$xlsx->sheetsCount():int
$xlsx->sheetNames():array
$xlsx->sheetName($worksheetIndex):string
$xlsx->sheetMeta($worksheetIndex = null):array sheets metadata (null = all sheets)
$xlsx->isHiddenSheet($worksheetIndex):bool
$xlsx->getStyles():array

```

Examples
--------

[](#examples)

### XLSX to html table

[](#xlsx-to-html-table)

```
echo SimpleXLSX::parse('book.xlsx')->toHTML();
```

or

```
if ( $xlsx = SimpleXLSX::parse('book.xlsx') ) {
	echo '';
	foreach( $xlsx->rows() as $r ) {
		echo ''.implode('', $r ).'';
	}
	echo '';
} else {
	echo SimpleXLSX::parseError();
}
```

or styled html table

```
if ( $xlsx = SimpleXLSX::parse('book_styled.xlsx') ) {
    echo $xlsx->toHTMLEx();
}
```

### XLSX read huge file, xlsx to csv

[](#xlsx-read-huge-file-xlsx-to-csv)

```
if ( $xlsx = SimpleXLSX::parse( 'xlsx/books.xlsx' ) ) {
    $f = fopen('book.csv', 'wb');
    // fwrite($f, chr(0xEF) . chr(0xBB) . chr(0xBF)); // UTF-8 BOM
    foreach ( $xlsx->readRows() as $r ) {
        fputcsv($f, $r); // fputcsv($f, $r, ';', '"', "\\", "\r\n");
    }
    fclose($f);
} else {
    echo SimpleXLSX::parseError();
}
```

### XLSX get sheet names and sheet indexes

[](#xlsx-get-sheet-names-and-sheet-indexes)

```
// Sheet numeration started 0

if ( $xlsx = SimpleXLSX::parse( 'xlsx/books.xlsx' ) ) {
    print_r( $xlsx->sheetNames() );
    print_r( $xlsx->sheetName( $xlsx->activeSheet ) );
}
```

```
Array
(
    [0] => Sheet1
    [1] => Sheet2
    [2] => Sheet3
)
Sheet2

```

### Using rowsEx() to extract cell info

[](#using-rowsex-to-extract-cell-info)

```
$xlsx = SimpleXLSX::parse('book.xlsx');
print_r( $xlsx->rowsEx() );
```

```
Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [type] => s
                    [name] => A1
                    [value] => ISBN
                    [href] =>
                    [f] =>
                    [format] =>
                    [s] => 0
                    [css] => color: #000000;font-family: Calibri;font-size: 17px;
                    [r] => 1
                    [hidden] =>
                    [width] => 13.7109375
                    [height] => 0
                    [comment] =>
                )

            [1] => Array
                (
                    [type] =>
                    [name] => B1
                    [value] => 2016-04-12 13:41:00
                    [href] => Sheet1!A1
                    [f] =>
                    [format] => m/d/yy h:mm
                    [s] => 0
                    [css] => color: #000000;font-family: Calibri;font-size: 17px;
                    [r] => 2
                    [hidden] => 1
                    [width] => 16.5703125
                    [height] => 0
                    [comment] => Serg: See transaction history

                )

```

typecell [type](https://c-rex.net/samples/ooxml/e1/Part4/OOXML_P4_DOCX_ST_CellType_topic_ID0E6NEFB.html)namecell name (A1, B11)valuecell value (1233, 1233.34, 2022-02-21 00:00:00, String)hrefinternal and external linksfformulasstyle index, use `$xlsx->cellFormats[ $index ]` to get stylecssgenerated cell CSSrrow indexhiddenhidden row or columnwidthwidth in [custom units](http://c-rex.net/samples/ooxml/e1/Part4/OOXML_P4_DOCX_col_topic_ID0ELFQ4.html)heightheight in points (pt, 1/72 in)commentCell comment as plain text### Select Sheet

[](#select-sheet)

```
$xlsx = SimpleXLSX::parse('book.xlsx');
// Sheet numeration started 0, we select second worksheet
foreach( $xlsx->rows(1) as $r ) {
// ...
}
```

### Get sheet by index

[](#get-sheet-by-index)

```
$xlsx = SimpleXLSX::parse('book.xlsx');
echo 'Sheet Name 2 = '.$xlsx->sheetName(1);
```

### XLSX::parse remote data

[](#xlsxparse-remote-data)

```
if ( $xlsx = SimpleXLSX::parse('https://www.example.com/example.xlsx' ) ) {
	$dim = $xlsx->dimension(1); // don't trust dimension extracted from xml
	$num_cols = $dim[0];
	$num_rows = $dim[1];
	echo $xlsx->sheetName(1).':'.$num_cols.'x'.$num_rows;
} else {
	echo SimpleXLSX::parseError();
}
```

### XLSX::parse memory data

[](#xlsxparse-memory-data)

```
// For instance $data is a data from database or cache
if ( $xlsx = SimpleXLSX::parseData( $data ) ) {
	print_r( $xlsx->rows() );
} else {
	echo SimpleXLSX::parseError();
}
```

### Get Cell (slow)

[](#get-cell-slow)

```
echo $xlsx->getCell(0, 'B2'); // The Hobbit
```

### DateTime helpers

[](#datetime-helpers)

```
// default SimpleXLSX datetime format is YYYY-MM-DD HH:MM:SS (ISO, MySQL)
echo $xlsx->getCell(0,'C2'); // 2016-04-12 13:41:00

// custom datetime format
$xlsx->setDateTimeFormat('d.m.Y H:i');
echo $xlsx->getCell(0,'C2'); // 12.04.2016 13:41

// unixstamp
$xlsx->setDateTimeFormat('U');
$ts = $xlsx->getCell(0,'C2'); // 1460468460
echo gmdate('Y-m-d', $ts); // 2016-04-12
echo gmdate('H:i:s', $ts); // 13:41:00

// raw excel value
$xlsx->setDateTimeFormat( NULL ); // returns as excel datetime
$xd = $xlsx->getCell(0,'C2'); // 42472.570138889
echo gmdate('m/d/Y', $xlsx->unixstamp( $xd )); // 04/12/2016
echo gmdate('H:i:s', $xlsx->unixstamp( $xd )); // 13:41:00
```

### Rows with header values as keys

[](#rows-with-header-values-as-keys)

```
if ( $xlsx = SimpleXLSX::parse('books.xlsx')) {
    // Produce array keys from the array values of 1st array element
    $header_values = $rows = [];
    foreach ( $xlsx->rows() as $k => $r ) {
        if ( $k === 0 ) {
            $header_values = $r;
            continue;
        }
        $rows[] = array_combine( $header_values, $r );
    }
    print_r( $rows );
}
```

```
Array
(
    [0] => Array
        (
            [ISBN] => 618260307
            [title] => The Hobbit
            [author] => J. R. R. Tolkien
            [publisher] => Houghton Mifflin
            [ctry] => USA
        )
    [1] => Array
        (
            [ISBN] => 908606664
            [title] => Slinky Malinki
            [author] => Lynley Dodd
            [publisher] => Mallinson Rendel
            [ctry] => NZ
        )
)

```

### Debug

[](#debug)

```
use Shuchkin\SimpleXLSX;

ini_set('error_reporting', E_ALL );
ini_set('display_errors', 1 );

if ( $xlsx = SimpleXLSX::parseFile('books.xlsx', true ) ) {
    echo $xlsx->toHTML();
} else {
    echo SimpleXLSX::parseError();
}
```

### Classic OOP style

[](#classic-oop-style)

```
use SimpleXLSX;

$xlsx = new SimpleXLSX('books.xlsx'); // try...catch
if ( $xlsx->success() ) {
    foreach( $xlsx->rows() as $r ) {
        // ...
    }
} else {
    echo 'xlsx error: '.$xlsx->error();
}
```

More examples [here](https://github.com/shuchkin/simplexlsx/tree/master/examples)

### Error Codes

[](#error-codes)

SimpleXLSX::ParseErrno(), $xlsx-&gt;errno()

codemessagecomment1File not foundWhere file? UFO?2Unknown archive formatZIP?3XML-entry parser errorbad XML4XML-entry not foundbad ZIP archive5Entry not foundFile not found in ZIP archive6Worksheet not foundNot exists

###  Health Score

66

—

FairBetter than 99% of packages

Maintenance71

Regular maintenance activity

Popularity71

Solid adoption and visibility

Community42

Growing community involvement

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 94.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~56 days

Recently: every ~89 days

Total

45

Last Release

164d ago

Major Versions

0.9.11 → 1.0.122022-02-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/551f9169d9efadfa85ff5ff512eab17e9219ba10e42636d9a31f1021a1027395?d=identicon)[shuchkin](/maintainers/shuchkin)

---

Top Contributors

[![shuchkin](https://avatars.githubusercontent.com/u/315872?v=4)](https://github.com/shuchkin "shuchkin (192 commits)")[![tim-bezhashvyly](https://avatars.githubusercontent.com/u/462687?v=4)](https://github.com/tim-bezhashvyly "tim-bezhashvyly (2 commits)")[![dshumko](https://avatars.githubusercontent.com/u/8360276?v=4)](https://github.com/dshumko "dshumko (1 commits)")[![epif4nio](https://avatars.githubusercontent.com/u/26820396?v=4)](https://github.com/epif4nio "epif4nio (1 commits)")[![hackimov](https://avatars.githubusercontent.com/u/49386760?v=4)](https://github.com/hackimov "hackimov (1 commits)")[![matheuseduardo](https://avatars.githubusercontent.com/u/99185?v=4)](https://github.com/matheuseduardo "matheuseduardo (1 commits)")[![mtwango](https://avatars.githubusercontent.com/u/40821415?v=4)](https://github.com/mtwango "mtwango (1 commits)")[![smgallo](https://avatars.githubusercontent.com/u/2301909?v=4)](https://github.com/smgallo "smgallo (1 commits)")[![acomjean](https://avatars.githubusercontent.com/u/3139639?v=4)](https://github.com/acomjean "acomjean (1 commits)")[![wimwinterberg](https://avatars.githubusercontent.com/u/806945?v=4)](https://github.com/wimwinterberg "wimwinterberg (1 commits)")[![ascweb](https://avatars.githubusercontent.com/u/3051143?v=4)](https://github.com/ascweb "ascweb (1 commits)")

---

Tags

phpparserexcelxlsxreaderbackend

### Embed Badge

![Health badge](/badges/shuchkin-simplexlsx/health.svg)

```
[![Health](https://phpackages.com/badges/shuchkin-simplexlsx/health.svg)](https://phpackages.com/packages/shuchkin-simplexlsx)
```

###  Alternatives

[shuchkin/simplexlsxgen

Export data to Excel XLSx file. PHP XLSX generator.

1.1k2.2M16](/packages/shuchkin-simplexlsxgen)[openspout/openspout

PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

1.1k57.6M131](/packages/openspout-openspout)[avadim/fast-excel-reader

Lightweight and very fast XLSX Excel Spreadsheet Reader in PHP

104608.4k6](/packages/avadim-fast-excel-reader)[shuchkin/simplexls

Parse and retrieve data from old format Excel XLS files. MS Excel 97 workbooks PHP reader.

212588.3k2](/packages/shuchkin-simplexls)[akeneo-labs/spreadsheet-parser

Akeneo Spreadsheet parser. Reads XLXS files from Microsoft Excel and Open Office

147598.3k6](/packages/akeneo-labs-spreadsheet-parser)[shuchkin/simplecsv

Parse and retrieve data from CSV files. Export data to CSV.

5192.4k](/packages/shuchkin-simplecsv)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
