sostheng / entity-portation-bundle
这是一个允许您使用PHPExcel简单导出实体数组的包
dev-master
2017-05-25 15:34 UTC
Requires
- php: >=5.3.2
- liuggio/excelbundle: dev-master
- symfony/framework-bundle: ~2.6|~3.0
Requires (Dev)
- phpunit/phpunit: ~4.6
- sensio/framework-extra-bundle: ~2.3|~3.0
- symfony/browser-kit: ~2.6|~3.0
- symfony/class-loader: ~2.6|~3.0
- symfony/finder: ~2.6|~3.0
- symfony/form: ~2.6|~3.0
- symfony/validator: ~2.6|~3.0
This package is not auto-updated.
Last update: 2024-09-29 02:49:41 UTC
README
这是一个允许您使用PHPExcel简单导出实体数组的包。
只需在您想要导出的类的元素上放置注解,EntityPortationBundle就会完成其余工作!传递要导出的实体列表并享受吧!
目前,只提供基本导出功能,但读取CSV/Excel文件并从中创建实体是计划中的。
请注意,此包仍在开发中,可能存在一些错误或奇怪的行为。请随时发送您的反馈!
许可证
安装
1 将其添加到composer.json
$composer require sostheng/entity-portation-bundle
2 在app/AppKernel.php
中注册该包
$bundles = array( // ... new SosthenG\EntityPortationBundle\EntityPortationBundle(), );
如何使用
此包使用注解来检测需要导出什么。要使用注解,您必须包含这两个类
use SosthenG\EntityPortationBundle\Annotation\EntityPortation; // To pass custom parameters for the export use SosthenG\EntityPortationBundle\Annotation\PortationGetter; // Required to tell which getter will be portable
以下是一个所有参数都已填充的示例
/** * @EntityPortation(csvDelimiter=";", sheetTitle="My sheet Title", fallBackValue="N/A") */ class MyClass { private $field; /** * @PortationGetter(label="Rôles", position="auto", visible=true, valueType="string") */ public function getField() { return $this->_field; } }
它们都是可选的,唯一必需的事情是在您想要用于导出的getter上使用@PortationGetter()注解。
您已经完成了最难的部分!现在,只需创建一个Export对象,添加或更改一些额外参数(如果需要),然后获取您的导出文件!
/** * @Route("export/{format}", name="export", requirements={"format" = "PDF|Excel2007|Excel5|CSV|HTML|OpenDocument"}) */ public function exportAction($format) { $entities = $this->getDoctrine()->getManager()->getRepository("Bundle:MyClass")->findAll(); $exporter = new Export($this->get("phpexcel"), $this->get("translator")); $exporter->setEntities($entities); // You can save the export as file or get a response from now, but if you want, you can change some parameters $prop = $exporter->getProperties(); // Returns the PhpExcel Properties object. $prop->setAuthor("You"); // Check the PHPExcel documentation for other parameters $exporter->setAllVisible(true); // etc. // Save the file $file = $exporter->saveAsFile($format, "web/files/myFileName"); // Extension is optionnal, it will be added if not filled // or return it as a Response return $exporter->getResponse($format, "myFileName"); }
一些文档
此包使用liuggio的ExcelBundle,这是一个PhpExcel集成包,用于Symfony。
此包的文档
暂不可用。让我先完成它:)