PHPackages                             xunlight/fast-excel-writer - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. xunlight/fast-excel-writer

ActiveLibrary[File &amp; Storage](/categories/file-storage)

xunlight/fast-excel-writer
==========================

Lightweight and very fast XLSX Excel Spreadsheet Writer in PHP

067PHP

Since Jan 26Pushed 3y agoCompare

[ Source](https://github.com/xunlight/fast-excel-writer)[ Packagist](https://packagist.org/packages/xunlight/fast-excel-writer)[ RSS](/packages/xunlight-fast-excel-writer/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

FastExcelWriter
===============

[](#fastexcelwriter)

Jump To:

- [Introduction](#introduction)
- [Changes in version 3](#changes-in-version-3)
- [Simple Example](#simple-example)
- [Advanced Example](#advanced-example)
- [Writing Cell Values](#writing-cell-values)
- [Direct Writing To Cells](#direct-writing-to-cells)
- [Cell Formats](#cell-formats)
- [Basic Cell Styles](#basic-cell-styles)
- [Formulas](#formulas)
- [Hyperlinks](#hyperlinks)
- [Set Directory For Temporary Files](#set-directory-for-temporary-files)

Introduction
------------

[](#introduction)

This library is designed to be lightweight, superfast and have minimal memory usage.

This library creates Excel compatible spreadsheets in XLSX format (Office 2007+), with just basic features supported:

- takes UTF-8 encoded input
- multiple worksheets
- supports currency/date/numeric cell formatting, simple formulas
- supports basic column, row and cell styling

**FastExcelWriter** vs **PhpSpreadsheet**

**PhpSpreadsheet** is a perfect library with wonderful features for reading and writing many document formats. **FastExcelWriter** can only write and only in xlsx format, but does it very fast and with minimal memory usage.

**FastExcelWriter**:

- 7-9 times faster
- uses less memory by 8-10 times
- supports writing huge 100K+ row spreadsheets

By the way, **FastExcelReader** also exists -

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

[](#installation)

Use `composer` to install **FastExcelWriter** into your project:

```
composer require avadim/fast-excel-writer

```

Also, you can download package and include autoload file of the library:

```
require 'path/to/fast-excel-writer/src/autoload.php';
```

Changes In Version 3
--------------------

[](#changes-in-version-3)

- Minimal version of PHP is 7.4.x
- All predefined formats are now case-insensitive and must start with '@' ('@date', '@money', etc)
- Method `setColumns()` was removed, use method `setColOptions()` instead
- Method `writeRow()` has third parameters: `writeRow($rowData, ?array $rowOptions, ?array cellOptions)`
- You can set auto width for columns
- Active hyperlinks supported

Usage
-----

[](#usage)

You can find usage examples below or in */demo* folder

### Simple Example

[](#simple-example)

```
use \avadim\FastExcelWriter\Excel;

$data = [
    ['2003-12-31', 'James', '220'],
    ['2003-8-23', 'Mike', '153.5'],
    ['2003-06-01', 'John', '34.12'],
];

$excel = Excel::create(['Sheet1']);
$sheet = $excel->getSheet();

// Write heads
$sheet->writeRow(['Date', 'Name', 'Amount']);

// Write data
foreach($data as $rowData) {
    $rowOptions = [
        'height' => 20,
    ];
    $sheet->writeRow($rowData);
}

$excel->save('simple.xlsx');
```

Also, you can download generated file to client (send to browser)

```
$excel->output('download.xlsx');
```

### Advanced Example

[](#advanced-example)

```
use \avadim\FastExcelWriter\Excel;

$head = ['Date', 'Name', 'Amount'];
$data = [
    ['2003-12-31', 'James', '220'],
    ['2003-8-23', 'Mike', '153.5'],
    ['2003-06-01', 'John', '34.12'],
];
$headStyle = [
    'font' => [
        'style' => 'bold'
    ],
    'text-align' => 'center',
    'vertical-align' => 'center',
    'border' => 'thin',
    'height' => 24,
];

$excel = Excel::create(['Sheet1']);
$sheet = $excel->getSheet();

$sheet->writeHeader($head, $headStyle);

$sheet
    ->setColFormats(['@date', '@text', '0.00'])
    ->setColWidths([12, 14, 5]);

$rowNum = 1;
foreach($data as $rowData) {
    $rowOptions = [
        'height' => 20,
    ];
    if ($rowNum % 2) {
        $rowOptions['fill'] = '#eee';
    }
    $sheet->writeRow($rowData);
}

$excel->save('simple.xlsx');
```

Also, you can download generated file to client (send to browser)

```
$excel->output('download.xlsx');
```

### Writing Cell Values

[](#writing-cell-values)

Usually, values is written sequentially, cell by cell, row by row. Writing to a cell moves the internal pointer to the next cell in the row, writing a row moves the pointer to the first cell of the next row.

```
use \avadim\FastExcelWriter\Excel;

$excel = Excel::create();
$sheet = $excel->getSheet();

// Sheet::writeCell(mixed value, ?array styles)
// Sheet::writeTo(string address, mixed value, ?array styles)
// Sheet::nextCell()

// Write number to A1 and pointer moves to the next cell (B1)
$sheet->writeCell(123);
// Write string to B1 (pointer in C1)
$sheet->writeCell('abc');
// Pointer moves to the next cell (D1) without value writing
$sheet->nextCell();
$style = [
    'color' => '#ff0000',
    'format' => '#,##0.00',
    'align' => 'center',
];
// Write to D1 value and style
$sheet->writeCell(0.9, $style);
// Merge cells range
$sheet->mergeCells('D1:F2');
// Write to B2 and moves pointer to C2. The pointer can only move from left to right and top to bottom
$sheet->writeTo('B2', 'value');
// Merge C3:E3, write value to merged cells and move pointer to F3
$sheet->writeTo('C3:E3', 'other value');
```

You can write values to rows

```
// Sheet::writeHeader(array header, ?array rowStyle)
// Sheet::writeRow(array row, ?array rowStyle)
// Sheet::nextRow()

// Write values to the current row and set format of columns A and B
$sheet->writeHeader(['title1' => '@integer', 'title2' => '@date']);

$data = [
    [184, '2022-01-23'],
    [835, '1971-12-08'],
    [760, '1997-05-11'],
];

foreach ($data as $rowData) {
    $sheet->writeRow($rowData);
}
```

### Direct Writing To Cells

[](#direct-writing-to-cells)

If you need to write directly to cells, you must define the area.

```
$area = $sheet->makeArea('B4:F12'); // Make write area from B4 to F12
$area = $sheet->makeArea('B4:12'); // Make write area from B4 to B12
$area = $sheet->beginArea('B4');  // Make write area from B4 to max column and max row

// Set style for single cell of area (new style will replace previous)
$area->setStyle('B4', $style1);
// Set additional style for single cell of area (new style wil be merged with previous)
$area->addStyle('B4', $style2);

$area->setStyle('D4:F6', $style2); // Set style for single cell of area

$area->setValue('A2:J2', 'This is demo XLSX-sheet', $headerStyle);

$area
    ->setValue('H4', 'Date', ['text-align' => 'right'])
    ->setValue('I4:J4', date('Y-m-d H:i:s'), ['font-style' => 'bold', 'format' => 'datetime', 'text-align' => 'left'])
;
```

### Height And Width

[](#height-and-width)

```
// Set height of row 2 to 33
$sheet->setRowHeight(2, 33);
// Set heights of several rows
$sheet->setRowHeights([1 => 20, 2 => 33, 3 => 40]);
// Write row data and set height
$sheet->writeRow($rowData, ['height' => 20]);

// Set width of column D to 24
$this->setColWidth('D', 24);
$this->setColOptions('D', ['width' => 24]);
// Set auto width
$this->setColWidth('D', 'auto');
$this->setColWidthAuto('D');
$this->setColOptions('D', ['width' => 'auto']);

// Set width of specific columns
$sheet->setColWidths(['B' => 10, 'C' => 'auto', 'E' => 30, 'F' => 40]);
$sheet->setColOptions(['B' => ['width' => 10], 'C' => ['width' => 'auto'], 'E' => ['width' => 30], 'F' => ['width' => 40]]);
// Set width of columns from 'A'
$sheet->setColWidths([10, 20, 30, 40]);
```

### Cell Formats

[](#cell-formats)

You can use simple and advanced formats

```
$excel = new \avadim\FastExcelWriter\Excel(['Formats']);
$sheet = $excel->getSheet();

$header = [
    'created' => '@date',
    'product_id' => '@integer',
    'quantity' => '#,##0',
    'amount' => '#,##0.00',
    'description' => '@string',
    'tax' => '[$$]#,##0.00;[RED]-[$$]#,##0.00',
];
$data = [
    ['2015-01-01', 873, 1, 44.00, 'misc', '=D2*0.05'],
    ['2015-01-12', 324, 2, 88.00, 'none', '=D3*0.15'],
];

$sheet->writeHeader($header);
foreach($data as $row) {
    $sheet->writeRow($row );
}

$excel->save('formats.xlsx');
```

Simple cell formats map to more advanced cell formats

simple formatsformat code@text@@string@@integer0@dateYYYY-MM-DD@datetimeYYYY-MM-DD HH:MM:SS@timeHH:MM:SS@money\[$$\]#,##0.00### Basic Cell Styles

[](#basic-cell-styles)

Font settings

```
use \avadim\FastExcelWriter\Style;

$style = [
    Style::FONT => [
        Style::FONT_NAME => 'Arial',
        Style::FONT_SIZE => 14,
        Style::FONT_STYLE => Style::FONT_STYLE_BOLD,
    ]
];
```

keyallowed valuesnameArial, Times New Roman, Courier New, Comic Sans MSsize8, 9, 10, 11, 12 ...stylebold, italic, underline, strikethrough or multiple ie: 'bold,italic'Border settings

```
use \avadim\FastExcelWriter\Style;

// simple border style
$style1 = [
    Style::BORDER => Style::BORDER_THIN
];

// border style with color
$style2 = [
    Style::BORDER => [
        Style::BORDER_ALL => [
            Style::BORDER_STYLE => Style::BORDER_THICK,
            Style::BORDER_COLOR => '#f00',
        ]
    ]
];

// extra border style
$style3 = [
    Style::BORDER => [
        Style::BORDER_TOP => Style::BORDER_NONE,
        Style::BORDER_LEFT => [
            Style::BORDER_STYLE => Style::BORDER_THICK,
            Style::BORDER_COLOR => '#f9009f',
        ],
        Style::BORDER_RIGHT => [
            Style::BORDER_STYLE => Style::BORDER_MEDIUM_DASH_DOT,
            Style::BORDER_COLOR => '#f00',
        ],
        Style::BORDER_BOTTOM => [
            Style::BORDER_STYLE => Style::BORDER_DOUBLE,
        ],
    ]
];
```

Other style settings

styleallowed valuescolor\#RRGGBB, ie: '#ff99cc' or '#f9c'fill\#RRGGBB, ie: '#eeffee' or '#efe'text-align'general', 'left', 'right', 'justify', 'center'vertical-align'bottom', 'center', 'distributed'text-wraptrue, false### Formulas

[](#formulas)

Formulas must start with '='. If you want to write the formula as a text, use a backslash. Setting the locale allows the use of national language function names. You can use both A1 and R1C1 notations in formulas

```
use \avadim\FastExcelWriter\Excel;

$excel = Excel::create(['Formulas']);
$sheet = $excel->getSheet();

// Set Russian locale
$excel->setLocale('ru');

$headRow = [];

$sheet->writeRow([1, random_int(100, 999), '=RC[-1]*0.1']);
$sheet->writeRow([2, random_int(100, 999), '=RC[-1]*0.1']);
$sheet->writeRow([3, random_int(100, 999), '=RC[-1]*0.1']);

$totalRow = [
    'Total',
    '=SUM(B1:B3)', // English function name
    '=СУММ(C1:C3)', // You can use Russian function name because the locale is 'ru'
];

$sheet->writeRow($totalRow);

$excel->save('formulas.xlsx');
```

Hyperlinks
----------

[](#hyperlinks)

You can insert URLs as active hyperlinks

```
// Write URL as simple string (not hyperlink)
$sheet->writeCell('https://google.com');

// Write URL as an active hyperlink
$sheet->writeCell('https://google.com', ['hyperlink' => true]);

// Write text with an active hyperlink
$sheet->writeCell('Google', ['hyperlink' => 'https://google.com']);
```

Set Directory For Temporary Files
---------------------------------

[](#set-directory-for-temporary-files)

The library uses temporary files to generate the XLSX-file. If not specified, they are created in the system temporary directory or in the current execution directory. But you can set the directory for temporary files.

```
use \avadim\FastExcelWriter\Excel;

Excel::setTempDir('/path/to/temp/dir'); // use this call before Excel::create()
$excel = Excel::create();

// Or alternative variant

$excel = Excel::create('SheetName', ['temp_dir' => '/path/to/temp/dir']);
```

Want to support FastExcelWriter?
--------------------------------

[](#want-to-support-fastexcelwriter)

if you find this package useful you can support and donate to me Or just give me star on GitHub :)

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 Bus Factor1

Top contributor holds 81.7% 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://avatars.githubusercontent.com/u/7010599?v=4)[xunlight](/maintainers/xunlight)[@xunlight](https://github.com/xunlight)

---

Top Contributors

[![aVadim483](https://avatars.githubusercontent.com/u/2246758?v=4)](https://github.com/aVadim483 "aVadim483 (49 commits)")[![xunlight](https://avatars.githubusercontent.com/u/7010599?v=4)](https://github.com/xunlight "xunlight (7 commits)")[![xdrew](https://avatars.githubusercontent.com/u/1220667?v=4)](https://github.com/xdrew "xdrew (2 commits)")[![albertbrufau](https://avatars.githubusercontent.com/u/590087?v=4)](https://github.com/albertbrufau "albertbrufau (1 commits)")[![maciejstepien-arch](https://avatars.githubusercontent.com/u/234204112?v=4)](https://github.com/maciejstepien-arch "maciejstepien-arch (1 commits)")

### Embed Badge

![Health badge](/badges/xunlight-fast-excel-writer/health.svg)

```
[![Health](https://phpackages.com/badges/xunlight-fast-excel-writer/health.svg)](https://phpackages.com/packages/xunlight-fast-excel-writer)
```

PHPackages © 2026

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