kematjaya/export-bundle

帮助导出多种格式的输出

2.1.1 2022-12-20 09:42 UTC

This package is auto-updated.

Last update: 2024-09-20 13:09:17 UTC


README

将symfony应用程序的模块导出到Excel、PDF等格式。如果您在此组件不在symfony应用程序外部安装,可以使用kematjaya/export

  1. 安装
composer require kematjaya/export-bundle
  1. 添加到config/bundles.php
...
Kematjaya\ExportBundle\ExportBundle::class => ['all' => true]
...
  1. 在控制器中使用
// src/Controller/TestController.php

...
use Kematjaya\Export\Processor\Excel\PHPSpreadsheetProcessor; // convert array to excel document
use Kematjaya\Export\Processor\Excel\HtmlToExcel;    // convert html to excel document
use Kematjaya\Export\Processor\PDF\DOMPDFProcessor; // convert html to PDF document
use Kematjaya\Export\Manager\ManagerInterface;
...

public function pdfDocument(ManagerInterface $exportManager)
{
    // html to pdf 
    $pdf = $exportManager->render('<h3>TEST</h3>', new DOMPDFProcessor('doc.pdf'));

    // html to excel
    $htmlToExcel = $manager->render('<table></table>', new HtmlToExcel('doc.xls'));
    
    // array to excel
    $data = [
        ['a', 'b', 'c']
    ];
    $arrayToExcel = $manager->render($data, new PHPSpreadsheetProcessor());
}
...