liuggio/excelbundle
Composer 安装命令:
composer require liuggio/excelbundle
包简介
This is a Symfony2 Bundle helps you to read and write Excel files (including pdf, xlsx, odt), thanks to the PHPExcel library
README 文档
README
This bundle permits you to create, modify and read excel objects.
License
Version 2
This is the shiny new version. There is a big BC with the 1.* version, but unit tests, functional tests, and the new factory is very simple to use.
Version 1.*
If you have installed an old version, and you are happy to use it, you could find documentation and files in the tag v1.0.6, browse the code.
Things to know:
CSV is faster so if you have to create simple xls file, I encourage you to use the built-in function for csv: http://php.net/manual-lookup.php?pattern=csv&lang=en&scope=quickref
Installation
1 Add to composer.json to the require key
$composer require liuggio/excelbundle
2 Register the bundle in app/AppKernel.php
$bundles = array( // ... new Liuggio\ExcelBundle\LiuggioExcelBundle(), );
TL;DR
- Create an empty object:
$phpExcelObject = $this->get('phpexcel')->createPHPExcelObject();
- Create an object from a file:
$phpExcelObject = $this->get('phpexcel')->createPHPExcelObject('file.xls');
- Create a Excel5 and write to a file given the object:
$writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5'); $writer->save('file.xls');
- Create a Excel5 and create a StreamedResponse:
$writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5'); $response = $this->get('phpexcel')->createStreamedResponse($writer);
- Create a Excel file with an image:
$writer = $this->get('phpexcel')->createPHPExcelObject(); $writer->setActiveSheetIndex(0); $activesheet = $writer->getActiveSheet(); $drawingobject = $this->get('phpexcel')->createPHPExcelWorksheetDrawing(); $drawingobject->setName('Image name'); $drawingobject->setDescription('Image description'); $drawingobject->setPath('/path/to/image'); $drawingobject->setHeight(60); $drawingobject->setOffsetY(20); $drawingobject->setCoordinates('A1'); $drawingobject->setWorksheet($activesheet)
Not Only 'Excel5'
The list of the types are:
- 'Excel5'
- 'Excel2007'
- 'Excel2003XML'
- 'OOCalc'
- 'SYLK'
- 'Gnumeric'
- 'HTML'
- 'CSV'
Example
Fake Controller
The best place to start is the fake Controller at Tests/app/Controller/FakeController.php, that is a working example.
More example
You could find a lot of examples in the official PHPExcel repository https://github.com/PHPOffice/PHPExcel/tree/develop/Examples
For lazy devs
namespace YOURNAME\YOURBUNDLE\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\ResponseHeaderBag; class DefaultController extends Controller { public function indexAction($name) { // ask the service for a Excel5 $phpExcelObject = $this->get('phpexcel')->createPHPExcelObject(); $phpExcelObject->getProperties()->setCreator("liuggio") ->setLastModifiedBy("Giulio De Donato") ->setTitle("Office 2005 XLSX Test Document") ->setSubject("Office 2005 XLSX Test Document") ->setDescription("Test document for Office 2005 XLSX, generated using PHP classes.") ->setKeywords("office 2005 openxml php") ->setCategory("Test result file"); $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('A1', 'Hello') ->setCellValue('B2', 'world!'); $phpExcelObject->getActiveSheet()->setTitle('Simple'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $phpExcelObject->setActiveSheetIndex(0); // create the writer $writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5'); // create the response $response = $this->get('phpexcel')->createStreamedResponse($writer); // adding headers $dispositionHeader = $response->headers->makeDisposition( ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'stream-file.xls' ); $response->headers->set('Content-Type', 'text/vnd.ms-excel; charset=utf-8'); $response->headers->set('Pragma', 'public'); $response->headers->set('Cache-Control', 'maxage=1'); $response->headers->set('Content-Disposition', $dispositionHeader); return $response; } }
Contributors
Contribute
- fork the project
- clone the repo
- get the coding standard fixer:
wget http://cs.sensiolabs.org/get/php-cs-fixer.phar - before the PullRequest you should run the coding standard fixer with
php php-cs-fixer.phar fix -v .
liuggio/excelbundle 适用场景与选型建议
liuggio/excelbundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.39M 次下载、GitHub Stars 达 369, 最近一次更新时间为 2012 年 05 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Symfony2」 「excel」 「xls」 「bundle」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 liuggio/excelbundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 liuggio/excelbundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 liuggio/excelbundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This Symfony bundle integrates PhpSpreadsheet into Symfony using Twig.
PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine
PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine
Yii2 export extension
PHP Excel Library
Symfony2 Barcode Generator Bundle with Twig function extension
统计信息
- 总下载量: 6.39M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 377
- 点击次数: 31
- 依赖项目数: 21
- 推荐数: 4
其他信息
- 授权协议: MIT
- 更新时间: 2012-05-15