PHPackages                             nueip/phpspreadsheet-helper - 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. nueip/phpspreadsheet-helper

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

nueip/phpspreadsheet-helper
===========================

PHP Excel Helper - Write and read Spreadsheet with easy way based on PhpSpreadsheet

1.1.1(2y ago)05.8k11MITPHP

Since Jun 3Pushed 2y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (1)Versions (5)Used By (1)

PHPSpreadsheet Helper
=====================

[](#phpspreadsheet-helper)

PHP Excel Helper - Write and read Spreadsheet with easy way based on PhpSpreadsheet

[![Latest Stable Version](https://camo.githubusercontent.com/928cb6eab88e4f4519e2f3238b862e3a8853b4c5d035541f67a6a80d2ff41078/68747470733a2f2f706f7365722e707567782e6f72672f6e756569702f70687073707265616473686565742d68656c7065722f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/nueip/phpspreadsheet-helper)[![License](https://camo.githubusercontent.com/b4ce42a161a02c33df564a556bcaa53dbd9e3a575cc403a52d276b70d0d6c96b/68747470733a2f2f706f7365722e707567782e6f72672f6e756569702f70687073707265616473686565742d68656c7065722f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/nueip/phpspreadsheet-helper)

This library is a helper that encapsulate [PhpSpreadsheet](https://github.com/PHPOffice/PhpSpreadsheet) ([Documentation](https://phpspreadsheet.readthedocs.io/en/develop/)) for simple usage.

---

OUTLINE
-------

[](#outline)

- [PHPSpreadsheet Helper](#phpspreadsheet-helper)
    - [OUTLINE](#outline)
    - [DEMONSTRATION](#demonstration)
        - [Write to Excel](#write-to-excel)
        - [Read from Excel](#read-from-excel)
    - [REQUIREMENTS](#requirements)
    - [INSTALLATION](#installation)
    - [USAGE](#usage)
        - [Import &amp; Export](#import--export)
            - [newSpreadsheet()](#newspreadsheet)
            - [output()](#output)
            - [save()](#save)
        - [Get Rows](#get-rows)
            - [getRow()](#getrow)
            - [getRows()](#getrows)
        - [Add Rows](#add-rows)
            - [addRow()](#addrow)
            - [addRows()](#addrows)
            - [Attributes](#attributes)
        - [PhpSpreadsheet Original Usage Integration](#phpspreadsheet-original-usage-integration)
            - [Inject PhpSpreadsheet](#inject-phpspreadsheet)
            - [Extract PhpSpreadsheet](#extract-phpspreadsheet)
        - [Merge Cells](#merge-cells)
        - [Multiple Sheets](#multiple-sheets)
            - [setSheet()](#setsheet)
            - [getSheet()](#getsheet)
        - [Map of Coordinates &amp; Ranges](#map-of-coordinates--ranges)
        - [Style Attributes](#style-attributes)
        - [Columns Format](#columns-format)
        - [All Cells Format](#all-cells-format)
            - [setStyle()](#setstyle)
            - [setWrapText()](#setwraptext)
            - [setAutoSize()](#setautosize)
    - [LIMITATIONS](#limitations)
        - [Performance Issue](#performance-issue)

---

DEMONSTRATION
-------------

[](#demonstration)

### Write to Excel

[](#write-to-excel)

Output an Excel file to browser for download:

```
\nueip\phpSpreadsheet\Helper::newSpreadsheet()
    ->addRow(['ID', 'Name', 'Email'])
    ->addRows([
        ['1', 'Nick','myintaer@gmail.com'],
        ['2', 'Eric','eric@.....'],
    ])
    ->output('My Excel');
```

[![](https://raw.githubusercontent.com/nueip/phpspreadsheet-helper/master/img/demonstration.png)](https://raw.githubusercontent.com/nueip/phpspreadsheet-helper/master/img/demonstration.png)

### Read from Excel

[](#read-from-excel)

Import above excel file and return two-dimensional array data contained rows &gt; columns spread sheet:

```
$data = \nueip\phpSpreadsheet\Helper::newSpreadsheet('/tmp/My Excel.xlsx')
    ->getRows();

print_r($data);
```

Output result:

```
Array
(
    [0] => Array
        (
            [0] => ID
            [1] => Name
            [2] => Email
        )

    [1] => Array
        (
            [0] => 1
            [1] => Nick
            [2] => myintaer@gmail.com
        )

    [2] => Array
        (
            [0] => 2
            [1] => Eric
            [2] => eric@.....
        )

)

```

---

REQUIREMENTS
------------

[](#requirements)

This library requires the following:

- Dependent on [PhpSpreadsheet](https://phpspreadsheet.readthedocs.io/en/develop/#software-requirements)
    - PHP 5.6.0+
    - PHP extension php-zip enabled
    - PHP extension php-xml enabled
    - PHP extension php-gd2 enabled (if not compiled in)

---

INSTALLATION
------------

[](#installation)

Run Composer in your project:

```
composer require nueip/phpspreadsheet-helper

```

Then you could call it after Composer is loaded depended on your PHP framework:

```
require __DIR__ . '/vendor/autoload.php';

\nueip\phpSpreadsheet\Helper::newSpreadsheet();
```

---

USAGE
-----

[](#usage)

### Import &amp; Export

[](#import--export)

Simpliy read an Excel file then output to browser:

```
\nueip\phpSpreadsheet\Helper::newSpreadsheet('/tmp/excel.xlsx')
    ->addRow(['Modified A1'])
    ->output();
```

#### newSpreadsheet()

[](#newspreadsheet)

New or load an PhpSpreadsheet object

```
public static array newSpreadsheet(object|string $spreadSheet=null)
```

#### output()

[](#output)

Output file to browser

```
public static void output(string $filename='excel', string $format='Xlsx')
```

*`$format` list: `Xlsx`, `Xls`, `Html`, `Csv`, `Ods`*

#### save()

[](#save)

Save as file

```
public static string save(string $filename='excel', string $format='Xlsx')
```

*Example:*

```
\nueip\phpSpreadsheet\Helper::newSpreadsheet()
    ->addRow(['Add A1'])
    ->save("/tmp/save");
// /tmp/save.xlsx
```

### Get Rows

[](#get-rows)

#### getRow()

[](#getrow)

Get data of a row from the actived sheet of PhpSpreadsheet

```
public static array getRow(boolean $toString=true, array $options=[], callable $callback=null)
```

*Example:*

```
use \nueip\phpSpreadsheet\Helper;

$row1 = Helper::newSpreadsheet($filepath)
    ->getRow();

$row2 = Helper::getRow();

print_r($row1);
print_r($row2);
```

*Example of fetching content per each row ([Example Code](https://github.com/nueip/phpspreadsheet-helper/blob/master/demo/get-row-loop.php)):*

```
$helper = \nueip\phpSpreadsheet\Helper::newSpreadsheet($filepath);

while ($row = $helper->getRow()) {
    // Each row data process
}
```

#### getRows()

[](#getrows)

Get rows from the actived sheet of PhpSpreadsheet

```
public static array getRows(boolean $toString=true, array $options=[], callable $callback=null)
```

*[Example of getRows()](#read-from-excel)*

### Add Rows

[](#add-rows)

#### addRow()

[](#addrow)

Add a row to the actived sheet of PhpSpreadsheet

```
public static self addRow(array $rowData, array $rowAttributes=null)
```

*`$rowData` value: An array contains string or [array of attributes](#attributes) for each cell*
*`$rowAttributes` value: string or [array of attributes](#attributes) for each cell of a row*

*[Example of addRow()](#write-to-excel)*

*Example of setting attributes for each cell:*

```
\nueip\phpSpreadsheet\Helper::newSpreadsheet()
    ->addRow([['value'=>'ID'], ['value'=>'Name'], ['value'=>'Email']])
    ->addRow(['ID', 'Name', 'Email']);
```

*Example of setting attributes for each row:*

```
\nueip\phpSpreadsheet\Helper::newSpreadsheet()
    // Set width as 25 to all cells of this row
    ->addRow([['value'=>'ID'], ['value'=>'Name'], ['value'=>'Email']], ['width'=>25]);
```

#### addRows()

[](#addrows)

Add rows to the actived sheet of PhpSpreadsheet

```
public static self addRows(array $data, array $rowAttributes=null)
```

*`$data` value: array of each $rowData from `addRow()`*
*`$rowAttributes` value: string or [array of attributes](#attributes) for each row*

*[Example of addRows()](#write-to-excel)*

#### Attributes

[](#attributes)

Attributes is a standard array for defining a cell or even a row, the keys are as follows:

`key`, `value`, [`col`](#merge-cells), [`row`](#merge-cells), [`skip`](#merge-cells), [`width`](#columns-format), [`style`](#style-attribute)

### PhpSpreadsheet Original Usage Integration

[](#phpspreadsheet-original-usage-integration)

This helper is flexible that you could inject or extract original PhpSpreadsheet with it, when you need to manipulate some Phpspreadsheet methods integrated with Helper.

#### Inject PhpSpreadsheet

[](#inject-phpspreadsheet)

```
// Get a new PhpSpreadsheet object
$objSpreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet;
$objSpreadsheet->getProperties()
    ->setCreator("Nick Tsai")
    ->setTitle("Office 2007 XLSX Document");

// Get the actived sheet object from PhpSpreadsheet
$objSheet = $objSpreadsheet->setActiveSheetIndex(0);
$objSheet->setTitle('Sheet');
$objSheet->setCellValue('A1', 'SN');

// Inject PhpSpreadsheet Object and Sheet Object to Helper
\nueip\phpSpreadsheet\Helper::newSpreadsheet($objSpreadsheet)
    ->setSheet($objSheet)
    ->setRowOffset(1) // Point to 1nd row from 0
    ->addRows([
        ['1'],
        ['2'],
    ])
    ->output();
```

#### Extract PhpSpreadsheet

[](#extract-phpspreadsheet)

```
use \nueip\phpSpreadsheet\Helper;

Helper::newSpreadsheet()
    ->setSheet(0, 'Sheet')
    ->addRow(['SN']);

// Get the PhpSpreadsheet object created by Helper
$objSpreadsheet = Helper::getSpreadsheet();
$objSpreadsheet->getProperties()
    ->setCreator("Nick Tsai")
    ->setTitle("Office 2007 XLSX Document");

// Get the actived sheet object created by Helper
$objSheet = Helper::getSheet();
$objSheet->setCellValue('A2', '1');
$objSheet->setCellValue('A3', '2');

Helper::output();
```

### Merge Cells

[](#merge-cells)

It's easy to merge cells by defining each cell's span attributes:

- `row` : Number of rowspan cells to merge with
- `col` : Number of colspan cells to merge with
- `skip` : Number of colspan cells to merge with

```
\nueip\phpSpreadsheet\Helper::newSpreadsheet()
    ->addRows([
        [['value'=>'SN', 'row'=>2], ['value'=>'Language', 'col'=>2], ['value'=>'Block', 'row'=>2, 'col'=>2]],
        ['','English','繁體中文',['skip'=>2]],
    ])
    ->addRows([
        ['1', 'Computer','電腦','#15'],
        ['2', 'Phone','手機','#4','#62'],
    ])
    ->output('Merged Excel');
```

### Multiple Sheets

[](#multiple-sheets)

#### setSheet()

[](#setsheet)

Set an active PhpSpreadsheet Sheet

```
public static self setSheet($sheet=0, $title=NULL, $normalizeTitle=false)
```

#### getSheet()

[](#getsheet)

Get PhpSpreadsheet Sheet object from cache

```
public static object getSheet($identity=null, $autoCreate=false)
```

*Example:*

```
use \nueip\phpSpreadsheet\Helper;

Helper::newSpreadsheet()
    ->setSheet(0, 'First Sheet')
    ->addRow(['Sheet Index', 'Sheet Count'])
    ->addRows([
        [Helper::getActiveSheetIndex(), Helper::getSheetCount()],
    ]);

// Set another sheet object without giving index
Helper::setSheet(null, '2nd Sheet')
    ->addRow(['Sheet Index', 'Sheet Count'])
    ->addRows([
        [Helper::getActiveSheetIndex(), Helper::getSheetCount()],
    ]);

// Get a sheet which does not exsit with auto creating it
$obj = Helper::getSheet('3nd Sheet', true);

// Set a sheet with the title which has been auto-normalized
Helper::setSheet(null, '*This [sheet] name has been auto-nomalizing', true)
    ->addRow(['Sheet Index', 'Sheet Count'])
    ->addRows([
        [Helper::getActiveSheetIndex(), Helper::getSheetCount()],
    ]);

Helper::output('MultiSheets');
```

- `getActiveSheetIndex()`: Get active sheet index
- `getSheetCount()`: Get sheet count

### Map of Coordinates &amp; Ranges

[](#map-of-coordinates--ranges)

```
use \nueip\phpSpreadsheet\Helper;

Helper::newSpreadsheet()
    ->addRows([
        [
            ['value'=>'SN', 'row'=>2, 'key'=>'sn'],
            ['value'=>'Language', 'col'=>2, 'key'=>'lang'],
            ['value'=>'Block', 'row'=>2, 'col'=>2, 'key'=>'block'],
        ],
        [
            '',
            ['value'=>'English', 'key'=>'lang-en'],
            ['value'=>'繁體中文', 'key'=>'lang-zh'],
            ['skip'=>2, 'key'=>'block-skip'],
        ],
    ])
    ->addRows([
        ['1', 'Computer','電腦','#15'],
        ['2', 'Phone','手機','#4','#62'],
    ]);
// ->output('Merged Excel');

print_r(Helper::getCoordinateMap());
print_r(Helper::getRangeMap());
// print_r(Helper::getColumnMap());
// print_r(Helper::getRowMap());
echo "sn start cell: ". Helper::getCoordinateMap('sn');
echo "\nsn start column: ". Helper::getColumnMap('sn');
echo "\nsn start row: ". Helper::getRowMap('sn');
echo "\nsn range: ". Helper::getRangeMap('sn');
echo "\nAll range: ". Helper::getRangeAll();
```

The result could be:

```
Array
(
    [sn] => A1
    [lang] => B1
    [block] => D1
    [lang-en] => B2
    [lang-zh] => C2
    [block-skip] => D2
)
Array
(
    [sn] => A1:A2
    [lang] => B1:C1
    [block] => D1:E2
    [lang-en] => B2:B2
    [lang-zh] => C2:C2
    [block-skip] => D2:E2
)
sn start cell: A1
sn start column: A
sn start row: 1
sn range: A1:A2
All range: A1:E4

```

### Style Attributes

[](#style-attributes)

The style attribute could be set on a [single cell](#addrow), a [single row](#addrow) or even a [range of cells](#setstyle).

- `style`: a attribute refers to `applyFromArray()` for styling

```
\nueip\phpSpreadsheet\Helper::newSpreadsheet()
    // Each cell with each style attributes
    ->addRow([
        'Percentage',
        '10%',
        ['value'=>'content', 'style'=> [
            'font' => [
                'bold' => true,
                'color' => ['argb' => 'FFFF0000']
            ],
            'alignment' => ['horizontal' => 'right'],
            'borders' => [
                'top' => ['borderStyle' => 'thin'],
            ],
            'fill' => [
                'fillType' => 'linear',
                'rotation' => 90,
                'startColor' => ['argb' => 'FFA0A0A0'],
                'endColor' => ['argb' => 'FFFFFFFF'],
            ],
        ]],
        ['value'=>'10000', 'style'=> [
            'numberFormat' => [
                'formatCode' => '#,##0',
            ],
        ]],
    ])
    // Row with thousands separator format style
    ->addRow(['1000', '2000', '3000', '4000'], ['style' => [
        'numberFormat' => [
            // const FORMAT_NUMBER_COMMA_SEPARATED1 = '#,##0.00';
            'formatCode' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
        ],
    ]])
    // Row with percentage format style
    ->addRow(['0.1', '0.15', '0.3145', '0.855'], ['style' => [
        'numberFormat' => [
            // const FORMAT_PERCENTAGE_00 = '0.00%';
            'formatCode' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_PERCENTAGE_00,
        ],
    ]])
    ->output();
```

> Style array key/value/constant refers [Valid array keys for style `applyFromArray()`](https://phpspreadsheet.readthedocs.io/en/develop/topics/recipes/#valid-array-keys-for-style-applyfromarray) or [Source Classes](https://github.com/PHPOffice/PhpSpreadsheet/tree/master/src/PhpSpreadsheet/Style)

### Columns Format

[](#columns-format)

The options for each cell data:

- `width`: setWidth() for the column

```
\nueip\phpSpreadsheet\Helper::newSpreadsheet()
    ->addRow([['value'=>'ID', 'width'=>10], ['value'=>'Name', 'width'=>25], ['value'=>'Email', 'width'=>50]])
    ->addRows([
        ['1', 'Nick','myintaer@gmail.com'],
        ['2', 'Eric','eric@.....'],
    ])
    ->output('My Excel');
```

### All Cells Format

[](#all-cells-format)

This section focuses on applying all actived cells or ranged cells on the sheet, not just effecting single cell, row or column.

#### setStyle()

[](#setstyle)

Set Style for all actived cells or set by giving range to the actived sheet

```
public static self setStyle(array $styleArray, string $range=NULL)
```

*Example:*

```
\nueip\phpSpreadsheet\Helper::newSpreadsheet()
    ->addRow(['Title', 'Content'])
    ->addRows([
        ['Basic Plan', "*Interface\n*Search Tool"],
        ['Advanced Plan', "*Interface\n*Search Tool\n*Statistics"],
    ])
    ->setWrapText()
    // ->setWrapText('B2')
    ->setAutoSize()
    // ->setAutoSize('B')
    ->setStyle([
        'borders' => [
            'inside' => ['borderStyle' => 'hair'],
            'outline' => ['borderStyle' => 'thin'],
        ],
        'fill' => [
            'fillType' => 'solid',
            'startColor' => ['argb' => 'FFCCCCCC'],
        ],
    ])
    ->output('Formatted Excel');
```

#### setWrapText()

[](#setwraptext)

Set WrapText for all actived cells or set by giving range to the actived sheet

```
public static self setWrapText(string $range=NULL, string $value=true)
```

#### setAutoSize()

[](#setautosize)

Set AutoSize for all actived cells or set by giving column range to the actived sheet

```
public static self setAutoSize(string $colAlphaStart=NULL, string $colAlphaEnd=NULL, boolean $value=true)
```

---

LIMITATIONS
-----------

[](#limitations)

### Performance Issue

[](#performance-issue)

If you're building large cell data with XLSX, you may face performance issue with memory usage and execution time.

[box/spout](https://github.com/box/spout) spreadsheet lirary supports building Excel file with high performance, you could use this library instead if you do not need more style and formatting requirements.

###  Health Score

32

—

LowBetter than 71% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 89.2% 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 ~666 days

Total

3

Last Release

772d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/942836f1d8cd35bae7a32f3d2998cf2c769179e8ea4026db206154de187a272e?d=identicon)[nueip](/maintainers/nueip)

![](https://www.gravatar.com/avatar/6bd60e16d77c1a5d8ade5391d4467721da169c487886b9f568586bcc66661050?d=identicon)[gunter1020](/maintainers/gunter1020)

---

Top Contributors

[![yidas](https://avatars.githubusercontent.com/u/12604195?v=4)](https://github.com/yidas "yidas (58 commits)")[![gunter1020](https://avatars.githubusercontent.com/u/15287859?v=4)](https://github.com/gunter1020 "gunter1020 (3 commits)")[![marshung24](https://avatars.githubusercontent.com/u/34496839?v=4)](https://github.com/marshung24 "marshung24 (3 commits)")[![dream-rhythm](https://avatars.githubusercontent.com/u/22325790?v=4)](https://github.com/dream-rhythm "dream-rhythm (1 commits)")

---

Tags

phpexcelPHPExcelphpspreadsheetsheetPhpSpreadsheet helper

### Embed Badge

![Health badge](/badges/nueip-phpspreadsheet-helper/health.svg)

```
[![Health](https://phpackages.com/badges/nueip-phpspreadsheet-helper/health.svg)](https://phpackages.com/packages/nueip-phpspreadsheet-helper)
```

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k144.3M709](/packages/maatwebsite-excel)[yidas/phpspreadsheet-helper

PHP Excel Helper - Write and read Spreadsheet with easy way based on PhpSpreadsheet

383144.5k3](/packages/yidas-phpspreadsheet-helper)

PHPackages © 2026

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