PHPackages                             xlsxwriter/excel - 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. xlsxwriter/excel

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

xlsxwriter/excel
================

Convert data to Excel file

1.0.2(1mo ago)029MITPHPPHP &gt;=8.5

Since Feb 28Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/Franco28/XLSXWriter)[ Packagist](https://packagist.org/packages/xlsxwriter/excel)[ RSS](/packages/xlsxwriter-excel/feed)WikiDiscussions xlsx/SpreadSheetBuilder Synced 3w ago

READMEChangelog (2)Dependencies (6)Versions (6)Used By (0)

XLSXWriter
==========

[](#xlsxwriter)

Overview
--------

[](#overview)

XLSXWriter is a small PHP library built on top of [PhpSpreadsheet](https://github.com/PHPOffice/PhpSpreadsheet). It provides a simple, chainable API for generating `.xlsx` files with headers, rows, offsets, and optional styling.

> **Requirement:** PHP 8.5+.

Features
--------

[](#features)

- Clean API for building spreadsheets and saving them to disk.
- Header and row styling with PhpSpreadsheet-style arrays.
- Offset support to position tables anywhere on the sheet.
- Minimal surface area: `setHeaders`, `addRow`, `applyStyleToRange`, `write`.

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

[](#installation)

```
composer require xlsxwriter/excel
```

Quick Start
-----------

[](#quick-start)

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

use XLSXWriter\ExcelWriter;

$writer = new ExcelWriter();

$writer->setHeaders(['Name', 'Age', 'Email'])
       ->addRow(['John Doe', 30, 'john@example.com'])
       ->addRow(['Jane Doe', 25, 'jane@example.com']);

if ($writer->write('output.xlsx')) {
    echo "Excel file created successfully.";
} else {
    echo "Error creating Excel file.";
}
```

Header Styling
--------------

[](#header-styling)

`setHeaders()` accepts a style array compatible with PhpSpreadsheet. You can also disable borders by passing `['borders' => false]`.

```
use XLSXWriter\ExcelWriter;

$writer = new ExcelWriter();

$headerStyle = [
    'font' => [
        'size' => 16,
        'name' => 'Calibri',
        'bold' => true,
        'color' => ['argb' => 'FF003366'],
    ],
    'fill' => [
        'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
        'startColor' => ['argb' => 'FFF2F2F2'],
    ],
];

$writer->setHeaders(['Product', 'Qty', 'Price'], $headerStyle)
       ->addRow(['Keyboard', 2, 49.90])
       ->addRow(['Mouse', 1, 19.90])
       ->write('styled_headers.xlsx');
```

Row Styling
-----------

[](#row-styling)

`addRow()` also accepts a style array. This applies only to the row you are adding.

```
use XLSXWriter\ExcelWriter;

$writer = new ExcelWriter();

$writer->setHeaders(['Date', 'Total']);

$writer->addRow(['2024-01-01', 1000], [
    'fill' => [
        'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
        'startColor' => ['argb' => 'FFEAF7FF'],
    ],
]);

$writer->addRow(['2024-01-02', 1500], [
    'borders' => false,
]);

$writer->write('row_styles.xlsx');
```

Offsets (Positioning)
---------------------

[](#offsets-positioning)

Use `setOffset($columnIndex, $rowIndex)` to start the table at a specific cell.

```
use XLSXWriter\ExcelWriter;

$writer = new ExcelWriter();

// Start at D4 (column 4, row 4)
$writer->setOffset(4, 4)
       ->setHeaders(['City', 'Population'])
       ->addRow(['Madrid', 3223000])
       ->addRow(['Barcelona', 1620000])
       ->write('offset_example.xlsx');
```

Custom Range Styling
--------------------

[](#custom-range-styling)

You can style any range after building your table:

```
use XLSXWriter\ExcelWriter;

$writer = new ExcelWriter();

$writer->setHeaders(['A', 'B', 'C'])
       ->addRow([1, 2, 3])
       ->applyStyleToRange('A1:C2', [
           'font' => [
               'name' => 'Calibri',
               'size' => 11,
           ],
       ])
       ->write('range_style.xlsx');
```

Advanced Formatting (Dates, Currency, Alignment)
------------------------------------------------

[](#advanced-formatting-dates-currency-alignment)

PhpSpreadsheet lets you apply number formats and alignment. Use `applyStyleToRange()` after writing the data.

```
use XLSXWriter\ExcelWriter;

$writer = new ExcelWriter();

$writer->setHeaders(['Date', 'Amount', 'Status'])
       ->addRow(['2024-01-01', 1234.5, 'Paid'])
       ->addRow(['2024-01-02', 987.65, 'Pending']);

$writer->applyStyleToRange('A2:A3', [
    'numberFormat' => ['formatCode' => 'yyyy-mm-dd'],
]);

$writer->applyStyleToRange('B2:B3', [
    'numberFormat' => ['formatCode' => '"$"#,##0.00'],
    'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT],
]);

$writer->applyStyleToRange('C2:C3', [
    'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER],
]);

$writer->write('formatted.xlsx');
```

Laravel Example
---------------

[](#laravel-example)

```
namespace App\Http\Controllers;

use XLSXWriter\ExcelWriter;

class ReportController extends Controller
{
    public function download()
    {
        $writer = new ExcelWriter();

        $writer->setHeaders(['Name', 'Score'])
               ->addRow(['Alice', 95])
               ->addRow(['Bob', 88]);

        $path = storage_path('app/reports/report.xlsx');

        if ($writer->write($path)) {
            return response()->download($path)->deleteFileAfterSend(true);
        }

        return response('Error creating Excel file.', 500);
    }
}
```

API Summary
-----------

[](#api-summary)

```
ExcelWriter::setOffset(int $columns, int $rows): self
ExcelWriter::setHeaders(array $headers, array $customStyle = []): self
ExcelWriter::addRow(array $row, array $customStyle = []): self
ExcelWriter::applyStyleToRange(string $range, array $styleArray): self
ExcelWriter::write(string $filePath): bool
```

Error Handling
--------------

[](#error-handling)

- `write()` returns `true` on success and `false` on failure.
- If you need error details, wrap the call or update `FileSaver` to log exceptions.

Limitations and Performance Notes
---------------------------------

[](#limitations-and-performance-notes)

- This library writes in memory through PhpSpreadsheet; very large datasets will use significant RAM.
- Auto-sizing columns (if you enable it) can be slow on large sheets.
- Streaming writers are not included here; if you need huge exports, consider a streaming approach in PhpSpreadsheet.

Compatibility
-------------

[](#compatibility)

- PHP 8.5+
- PhpSpreadsheet ^5.4

Testing
-------

[](#testing)

```
composer install
composer test
```

Roadmap
-------

[](#roadmap)

- Multi-sheet support.
- Optional streaming writer for large exports.
- Helper methods for common formats (dates, currency, percentages).

Contributing
------------

[](#contributing)

Issues and PRs are welcome. Keep changes small and focused, and include a short description and tests when applicable.

Changelog
---------

[](#changelog)

See `composer.json` for the current version.

Notes
-----

[](#notes)

- `setHeaders()` accepts both indexed arrays (`['Name', 'Email']`) and associative arrays (`['Name' => 'string']`).
- `write()` returns `true` on success and `false` on failure.
- Styling arrays follow the PhpSpreadsheet format. See their docs for full options.

###  Health Score

44

—

FairBetter than 91% of packages

Maintenance90

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~214 days

Total

3

Last Release

53d ago

PHP version history (3 changes)1.0.0PHP &gt;=8.3

1.0.1PHP &gt;=8.4

1.0.2PHP &gt;=8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/f8a267f4ef082422994b403ec1b442b26167decb80b817a8aa398f178f77bb19?d=identicon)[Franco28](/maintainers/Franco28)

---

Top Contributors

[![Franco28](https://avatars.githubusercontent.com/u/11141854?v=4)](https://github.com/Franco28 "Franco28 (57 commits)")

---

Tags

composercomposer-librarylaravellaravel-frameworkphplibraryexcelxlsxwriter

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/xlsxwriter-excel/health.svg)

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

###  Alternatives

[mk-j/php_xlsxwriter

PHP Library to write XLSX files

1.9k8.5M30](/packages/mk-j-php-xlsxwriter)[shuchkin/simplexlsxgen

Export data to Excel XLSx file. PHP XLSX generator.

1.1k2.4M26](/packages/shuchkin-simplexlsxgen)[avadim/fast-excel-writer

Lightweight and very fast XLSX Excel Spreadsheet Writer in PHP

3021.3M9](/packages/avadim-fast-excel-writer)[avadim/fast-excel-reader

Lightweight and very fast XLSX Excel Spreadsheet and CSV Reader in PHP

106693.8k9](/packages/avadim-fast-excel-reader)[avadim/fast-excel-templator

Lightweight and very fast Excel Spreadsheet generator from XLSX-templates in PHP

20124.5k](/packages/avadim-fast-excel-templator)[maksimovic/php-xlsx-writer

PHP Library to write XLSX files

1451.3k](/packages/maksimovic-php-xlsx-writer)

PHPackages © 2026

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