tanur / excel-bundle
Symfony Bundle,用于读取或写入 Excel 文件(包括 pdf、xlsx、odt),使用 phpoffice/phpspreadsheet 库(phpoffice/phpexcel 的替代品,已弃用)
1.0.2
2023-11-02 13:06 UTC
Requires
- php: >=7.2
- phpoffice/phpspreadsheet: ~1.0
- symfony/config: ^3.0|^3.2|^4.0|^5.0|^6.0
- symfony/dependency-injection: ^3.0|^3.2|^4.0|^5.0|^6.0
- symfony/framework-bundle: ^3.0|^3.2|^4.0|^5.0|^6.0
- symfony/http-foundation: ^3.0|^3.2|^4.0|^5.0|^6.0
- symfony/http-kernel: ^3.0|^3.2|^4.0|^5.0|^6.0
Requires (Dev)
- php: >=7.2
- phpunit/phpunit: ~6.5
- sensio/framework-extra-bundle: ^3.0|^3.2|^4.0|^5.0|^6.0
- squizlabs/php_codesniffer: ~2
Suggests
- onurb/doctrine-yuml-bundle: Use this bundle to generate mapping graph from your entities
This package is auto-updated.
Last update: 2024-08-31 00:32:24 UTC
README
安装
1 将以下内容添加到 composer.json 的 require
键中
composer require tanur/excel-bundle
或手动在 composer.json 中添加
..., "require": { ..., "tanur/excel-bundle": "~1.0" }, ...
2 Symfony 3:在 app/AppKernel.php
中注册该 Bundle
$bundles = array( // ... new \Onurb\Bundle\ExcelBundle\OnurbExcelBundle(), );
Symfony 4:使用 symfony flex,Bundle 应已自动注册
// config/bundles.php return [ // ... Onurb\Bundle\ExcelBundle\OnurbExcelBundle::class => ['all' => true], ];
使用方法
创建电子表格
$spreadsheet = $this->get('phpspreadsheet')->createSpreadsheet();
从现有文件创建电子表格
$spreadsheet = $this->get('phpspreadsheet')->createSpreadsheet('file.xlsx');
根据对象创建 Excel5 并写入文件
$writer = $this->get('phpspreadsheet')->createWriter($spreadsheet, 'Xls'); $writer->save('file.xls');
创建 Excel 2007 并创建 StreamedResponse
$writer = $this->get('phpspreadsheet')->createWriter($spreadsheet, 'Xlsx'); $response = $this->get('phpspreadsheet')->createStreamedResponse($writer);
创建带有图像的 Excel 文件
$writer = $this->get('phpspreadsheet')->createSpreadSheet(); $writer->setActiveSheetIndex(0); $activesheet = $writer->getActiveSheet(); $drawingobject = $this->get('phpspreadsheet')->createSpreadsheetWorksheetDrawing(); $drawingobject->setPath('/path/to/image') ->setName('Image name') ->setDescription('Image description') ->setHeight(60) ->setOffsetY(20) ->setCoordinates('A1') ->setWorksheet($activesheet);
创建读取器
$reader = $this->get('phpspreadsheet')->createReader('Xlsx');
支持文件类型
类型区分大小写。支持类型包括
Xlsx
:Excel 2007Xls
:Excel 5Xml
:Excel 2003 XMLSlk
:符号链接(SYLK)Ods
:Libre Office(ODS)Csv
:CSVHtml
:HTML
可选库可用于写入
Tcpdf
Mpdf
Dompdf
安装这些库
composer require tecnick.com/tcpdf composer require mpdf/mpdf composer require dompdf/dompdf
liuggio/Excelbundle 可移植性
对于已经使用 liuggio/ExcelBundle 并希望迁移到 phpspreadsheet 的用户,该 Bundle 应该直接兼容:保留了旧的 phpexcel 文件类型,已添加兼容性工厂,并且重新声明了 phpexcel 服务。
更多
请参阅官方 PhpSpreadsheet 文档。