PHPackages                             tdchien/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. tdchien/simplexlsx

ActiveLibrary

tdchien/simplexlsx
==================

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

04PHP

Since Jun 2Pushed 2y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

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)[![](https://camo.githubusercontent.com/85dc276f8d369fd3a0ac966e5207c3ff902db1139e82560aac480bd0ac871c90/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617472656f6e2d5f2d5f)](https://www.patreon.com/shuchkin)

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');
	foreach ( $xlsx->readRows() as $r ) {
		fwrite($f, implode(',',$r) . PHP_EOL);
	}
	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
                )

            [1] => Array
                (
                    [type] =>
                    [name] => B1
                    [value] => 2016-04-12 13:41:00
                    [href] =>
                    [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
                )

```

typecell [type](http://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_ST_CellType_topic_ID0E6NEFB.html#topic_ID0E6NEFB)namecell name (A1, B11)valuecell value (1233, 1233.34, 2022-02-21 00:00:00, String) fformulasstyle index, use `$xlsx->cellFormats[ $index ]` to get stylecssgenerated cell CSSrrow indexhiddenhidden row or columnwidthwidth in [custom units](http://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_col_topic_ID0ELFQ4.html)heightheight in points (pt, 1/72 in)### 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

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity22

Early-stage or recently created project

 Bus Factor1

Top contributor holds 93.1% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/67efca6a33c2a7d87493090902a3c09d80a39edd328fa2c994d904c2d1881d6b?d=identicon)[tdchien](/maintainers/tdchien)

---

Top Contributors

[![shuchkin](https://avatars.githubusercontent.com/u/315872?v=4)](https://github.com/shuchkin "shuchkin (175 commits)")[![tdchien](https://avatars.githubusercontent.com/u/1614393?v=4)](https://github.com/tdchien "tdchien (2 commits)")[![tim-bezhashvyly](https://avatars.githubusercontent.com/u/462687?v=4)](https://github.com/tim-bezhashvyly "tim-bezhashvyly (2 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)")[![dshumko](https://avatars.githubusercontent.com/u/8360276?v=4)](https://github.com/dshumko "dshumko (1 commits)")

### Embed Badge

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

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

PHPackages © 2026

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