https://github.com/90pixel/exporter-bundle
You can easily export your data to pdf or excel or any format.
https://github.com/90pixel/exporter-bundle
api bundle excel export pdf symfony
Last synced: about 2 months ago
JSON representation
You can easily export your data to pdf or excel or any format.
- Host: GitHub
- URL: https://github.com/90pixel/exporter-bundle
- Owner: 90pixel
- License: mit
- Created: 2021-09-29T13:50:11.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-08-16T23:30:11.000Z (10 months ago)
- Last Synced: 2025-08-17T01:11:10.932Z (10 months ago)
- Topics: api, bundle, excel, export, pdf, symfony
- Language: PHP
- Homepage:
- Size: 72.3 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Exporter Bundle
You can easily export your data to pdf or excel format.
Documentation
=============
* [Getting started](#getting-started)
* [Prerequisites](#prerequisites)
* [Installation](#installation)
* [Configuration](#configuration)
* [Usage](#usage)
* [Advanced Configuration](#advanced-configuration)
* [Custom filename](#custom-filename)
* [Custom twig template](#custom-twig-template)
* [Custom Exporter Class](#custom-exporter-class)
* [Advanced filename](#advanced-filename)
* [Add headers](#add-headers)
* [Access Query Builder](#access-query-builder)
* [Manage Filters (Extensions)](#manage-filters-extensions)
* [Custom Driver](#custom-driver)
* [Normalizer](#normalizer)
Getting started
===============
Prerequisites
-------------
This bundle requires Symfony 5.0+ and api platform.
Installation
------------
```bash
$ composer require 90pixel/exporter-bundle
```
### Register bundle
You can skip this step if you're using flex.
```php
return [
//...
DPX\ExporterBundle\ExporterBundle::class => ['all' => true],
];
```
Configuration
-------------
Add custom collection operation in your `entity`.
````php
/**
* @ApiResource(
* collectionOperations={
* "get",
* "export"={
* "method"="GET",
* "path"="/products/export"
* }
* }
* )
* ...
*/
````
then register your custom operation.
### Xlsx
```php
/**
* ...
* @ExporterConfig(
* operationName="export",
* headers={"ID", "Product", "Barcode", "Price"},
* )
* ...
*/
```
### Pdf
```php
/**
* ...
* @ExporterConfig(
* operationName="export",
* driver="dpx.exporter.driver.pdf",
* headers={"ID", "Product", "Barcode", "Price"},
* )
* ...
*/
```
Usage
-----
Go to ``http://localhost/api/products/export``
If it works, a file named `export.xlsx` will download.
Also you can customize filename.
For advanced usage, please see [advanced configuration](#advanced-configuration) section.
Advanced Configuration
======================
Custom Filename
---------------
```php
/**
* ...
* @ExporterConfig(
* operationName="export",
* filename="products.xlsx"
* )
* ...
*/
```
For more advanced filename, please see [advanced filename](#advanced-filename) section.
Custom Twig Template
--------------------
You can customize pdf style easily with your own twig template.
```php
/**
* ...
* @ExporterConfig(
* operationName="export",
* templateName="pdf/products.html.twig"
* )
* ...
*/
```
Custom Exporter Class
---------------------
You can customize few things easily with custom exporter class.
Generate exporter class.
```php
exporterManager = $exporterManager;
}
/**
* @return array
*/
public function getHeaders(): array
{
$isDiscount = $this->exporterManager->getRequest()->get('discount') === 'true';
return [
'ID',
'Product',
'Barcode',
$isDiscount ? 'Discount' : 'Price'
];
}
}
```
### Access Query Builder
```php
normalizer = $normalizer;
}
public function normalize($object, $format = null, array $context = []): array
{
$data = $this->normalizer->normalize($object, $format, $context);
$formatter = new NumberFormatter('en_GB', NumberFormatter::CURRENCY);
$price = $formatter->formatCurrency($object->getPrice(), 'EUR');
$data['price'] = $price;
return $data;
}
public function supportsNormalization($data, $format = null): bool
{
return $data instanceof Product;
}
public function hasCacheableSupportsMethod(): bool
{
return true;
}
}
```
## Author
[Muhep Atasoy](https://github.com/muhep06)
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details