PHPackages                             allegedwizard/php-spreadsheets - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. allegedwizard/php-spreadsheets

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

allegedwizard/php-spreadsheets
==============================

A spreadsheet parser wrapper utility, preferring OpenSpout with fallback to PhpSpreadsheet.

v1.0.5(1mo ago)07MITPHPPHP ^8.0

Since Mar 21Pushed 1mo agoCompare

[ Source](https://github.com/allegedwizard/php-spreadsheets)[ Packagist](https://packagist.org/packages/allegedwizard/php-spreadsheets)[ RSS](/packages/allegedwizard-php-spreadsheets/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (8)Versions (6)Used By (0)

PHP Spreadsheets
================

[](#php-spreadsheets)

This package is a wrapper utility interface for reading/writing spreadsheets, preferring OpenSpout with fallback to PhpSpreadsheet

Supports reading and writing XLSX, XLS, CSV, TXT, and ODS files.

Built on top of [OpenSpout](https://github.com/openspout/openspout) and [PhpSpreadsheet](https://github.com/PHPOffice/PhpSpreadsheet).

Created by [Alleged Wizard](https://allegedwizard.com).

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

[](#installation)

```
composer require allegedwizard/php-spreadsheets:^1.0
```

Reading
-------

[](#reading)

```
use AllegedWizard\PhpSpreadsheets\Spreadsheets;

$spreadsheet = new Spreadsheets('/path/to/file.xlsx');

// Get all rows as associative arrays keyed by header columns
$rows = $spreadsheet->toArray();

// Get column headers
$columns = $spreadsheet->getColumns();

// Get row counts per sheet
$counts = $spreadsheet->getRowCount();

// Check for multiple sheets
if ($spreadsheet->hasMultipleSheets()) {
    $sheetName = $spreadsheet->getSheetName($sheetKey);
}
```

### Limiting Columns

[](#limiting-columns)

```
$spreadsheet = new Spreadsheets('/path/to/file.xlsx');

// Return only specific columns
$spreadsheet->setLimitColumns(['Name', 'Email']);

// Wildcard support: return all columns starting with "Address"
$spreadsheet->setLimitColumns(['Address**']);

$rows = $spreadsheet->toArray();
```

### Overriding File Extension

[](#overriding-file-extension)

By default, the reader and writer infer the file type from the file extension. Use the third parameter to override this when the extension doesn't match the actual format.

```
// Treat a .txt file as CSV
$spreadsheet = new Spreadsheets('/path/to/file.txt', 'read', 'csv');
```

Writing
-------

[](#writing)

```
use AllegedWizard\PhpSpreadsheets\Spreadsheets;

$records = [
    ['Name' => 'Alice', 'Email' => 'alice@example.com'],
    ['Name' => 'Bob', 'Email' => 'bob@example.com'],
];

$spreadsheet = new Spreadsheets('/path/to/output.xlsx', 'write');
$spreadsheet->write($records);
```

### XLSX Header Formatting

[](#xlsx-header-formatting)

By default, XLSX output will freeze and bold the first row (header). To disable either behavior:

```
$spreadsheet = new Spreadsheets('/path/to/output.xlsx', 'write');
$spreadsheet->setFreezeHeader(false);
$spreadsheet->setBoldHeader(false);
$spreadsheet->write($records);
```

### Column Model

[](#column-model)

Define per-column width and type for styled XLSX output:

```
$model = [
    'Name'   => ['width' => 30, 'type' => 'string'],
    'Amount' => ['width' => 15, 'type' => 'currency'],
    'Date'   => ['width' => 20, 'type' => 'date'],
];

$spreadsheet->write($records, $model);
```

Supported types: `string`, `number`, `currency`, `date`, `boolean`, `link`, `image`, `formula`.

#### Link Type

[](#link-type)

The `link` type produces a clickable `=HYPERLINK(...)` formula in XLSX/XLS, and falls back to a plain `label (url)` string for CSV/ODS. Values may be either a plain URL string or an array with `url` and `label` keys:

```
$records = [
    ['Name' => 'Alice', 'Site' => ['url' => 'https://example.com', 'label' => 'Example']],
    ['Name' => 'Bob',   'Site' => 'https://openspout.org'],
];
$model = [
    'Name' => ['type' => 'string'],
    'Site' => ['type' => 'link'],
];

$spreadsheet->write($records, $model);
```

#### Image Type

[](#image-type)

The `image` type produces an `=IMAGE("url")` formula in XLSX/XLS. CSV/ODS fall back to the URL as plain text. Values may be a plain URL string or an array with `url` and optional `alt`:

```
$records = [
    ['Name' => 'Cat', 'Pic' => 'https://example.com/cat.jpg'],
    ['Name' => 'Dog', 'Pic' => ['url' => 'https://example.com/dog.png', 'alt' => 'A good dog']],
];
$model = [
    'Name' => ['type' => 'string'],
    'Pic'  => ['type' => 'image'],
];
```

Note: `=IMAGE()` is **Excel 365 (2023+) only**. Older Excel desktop, LibreOffice, and Google Sheets will not render the image.

#### Formula Type

[](#formula-type)

The `formula` type writes an arbitrary formula. The leading `=` is optional; the writer adds it if missing. CSV/ODS write the `computed` value if provided, otherwise the literal formula text:

```
$records = [
    ['Label' => 'Sum',    'Value' => '=SUM(1,2,3)'],
    ['Label' => 'Concat', 'Value' => ['formula' => '=CONCAT("a","b")', 'computed' => 'ab']],
];
$model = [
    'Label' => ['type' => 'string'],
    'Value' => ['type' => 'formula'],
];
```

### Multiple Sheets

[](#multiple-sheets)

```
// Rename the single sheet
$spreadsheet->write($records, [], 'My Sheet');

// Write multiple sheets
$multiSheetRecords = [
    'Users'  => $userRecords,
    'Orders' => $orderRecords,
];

$spreadsheet->write($multiSheetRecords, [], true);
```

### Optimized Write Mode

[](#optimized-write-mode)

When records are structured as separate `columns` and `rows` arrays:

```
$records = [
    'columns' => ['Name', 'Email'],
    'rows' => [
        ['Alice', 'alice@example.com'],
        ['Bob', 'bob@example.com'],
    ],
];

$spreadsheet->write($records, [], false, true);
```

CSV Utility
-----------

[](#csv-utility)

Convert an associative array to a CSV string:

```
$csv = Spreadsheets::arrayToCsv($records);
```

Testing
-------

[](#testing)

```
composer install
composer test
```

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance90

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

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 ~10 days

Total

5

Last Release

53d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/120d13ff55f4b8a218b1651de33eec9c2167b06968c4328e2ef9475174db3d76?d=identicon)[allegedwizard](/maintainers/allegedwizard)

---

Top Contributors

[![zawntech](https://avatars.githubusercontent.com/u/12899159?v=4)](https://github.com/zawntech "zawntech (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/allegedwizard-php-spreadsheets/health.svg)

```
[![Health](https://phpackages.com/badges/allegedwizard-php-spreadsheets/health.svg)](https://phpackages.com/packages/allegedwizard-php-spreadsheets)
```

###  Alternatives

[kimai/kimai

Kimai - Time Tracking

4.7k8.7k1](/packages/kimai-kimai)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

749284.3k35](/packages/civicrm-civicrm-core)[craftcms/feed-me

Import content from XML, RSS, CSV or JSON feeds into entries, categories, Craft Commerce products, and more.

293943.4k27](/packages/craftcms-feed-me)[filament/actions

Easily add beautiful action modals to any Livewire component.

1325.2M63](/packages/filament-actions)[laravel-enso/tables

Server-side data tables and export backend for Laravel Enso

63254.7k81](/packages/laravel-enso-tables)[yajra/laravel-datatables-export

Laravel DataTables Queued Export Plugin.

352.1M4](/packages/yajra-laravel-datatables-export)

PHPackages © 2026

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