https://github.com/slamdunk/openspout-helper
https://github.com/slamdunk/openspout-helper
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/slamdunk/openspout-helper
- Owner: Slamdunk
- License: mit
- Created: 2022-03-03T15:09:44.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-06-20T12:58:51.000Z (about 1 year ago)
- Last Synced: 2025-06-20T14:10:16.514Z (about 1 year ago)
- Language: PHP
- Size: 267 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Slam Openspout helper to create organized data table
[](https://packagist.org/packages/slam/openspout-helper)
[](https://packagist.org/packages/slam/openspout-helper)
[](https://github.com/Slamdunk/openspout-helper/actions/workflows/ci.yaml)
[](https://dashboard.stryker-mutator.io/reports/github.com/Slamdunk/openspout-helper/main)
## Installation
`composer require slam/openspout-helper`
## Usage
```php
use OpenSpout\Writer\Common\Creator\WriterEntityFactory;
use Slam\OpenspoutHelper as ExcelHelper;
require __DIR__ . '/vendor/autoload.php';
// Being an `iterable`, the data can be any dinamically generated content
// for example a PDOStatement set on unbuffered query
$users = [
[
'column_1' => 'John',
'column_2' => '123.45',
'column_3' => '2017-05-08',
],
[
'column_1' => 'Mary',
'column_2' => '4321.09',
'column_3' => '2018-05-08',
],
];
$columnCollection = new ExcelHelper\ColumnCollection(...[
new ExcelHelper\Column('column_1', 'User', 10, new ExcelHelper\CellStyle\Text()),
new ExcelHelper\Column('column_2', 'Amount', 15, new ExcelHelper\CellStyle\Amount()),
new ExcelHelper\Column('column_3', 'Date', 15, new ExcelHelper\CellStyle\Date()),
]);
$XLSXWriter = WriterEntityFactory::createXLSXWriter();
$XLSXWriter->openToFile(__DIR__.'/test.xlsx');
$activeSheet = $XLSXWriter->getCurrentSheet();
$activeSheet->setName('My Users');
$table = new ExcelHelper\Table($activeSheet, 'My Heading', $users);
$table->setColumnCollection($columnCollection);
(new ExcelHelper\TableWriter())->writeTable($XLSXWriter, $table);
$XLSXWriter->close();
```
Result:
