-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
241 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace Liuggio\ExcelBundle; | ||
|
||
use Symfony\Component\HttpFoundation\StreamedResponse; | ||
|
||
/** | ||
* Factory for PHPExcel objects, StreamedResponse, and PHPExcel_Writer_IWriter. | ||
* | ||
* @package Liuggio\ExcelBundle | ||
*/ | ||
class Factory | ||
{ | ||
private $phpExcelIO; | ||
|
||
public function __construct($phpExcelIO = '\PHPExcel_IOFactory') | ||
{ | ||
$this->phpExcelIO = $phpExcelIO; | ||
} | ||
/** | ||
* Creates an empty PHPExcel Object if the filename is empty, otherwise loads the file into the object. | ||
* | ||
* @param string $filename | ||
* | ||
* @return \PHPExcel | ||
*/ | ||
public function createPHPExcelObject($filename = null) | ||
{ | ||
if (null == $filename) { | ||
$phpExcelObject = new \PHPExcel(); | ||
|
||
return $phpExcelObject; | ||
} | ||
|
||
return call_user_func(array($this->phpExcelIO, 'load'), array($filename)); | ||
} | ||
|
||
/** | ||
* Create a writer given the PHPExcelObject and the type, | ||
* the type coul be one of PHPExcel_IOFactory::$_autoResolveClasses | ||
* | ||
* @param \PHPExcel $phpExcelObject | ||
* @param string $type | ||
* | ||
* | ||
* @return \PHPExcel_Writer_IWriter | ||
*/ | ||
public function createWriter(\PHPExcel $phpExcelObject, $type = 'Excel5') | ||
{ | ||
return call_user_func(array($this->phpExcelIO, 'createWriter'), $phpExcelObject, $type); | ||
} | ||
|
||
/** | ||
* Stream the file as Response. | ||
* | ||
* @param \PHPExcel_Writer_IWriter $writer | ||
* @param int $status | ||
* @param array $headers | ||
* | ||
* @return StreamedResponse | ||
*/ | ||
public function createStreamedResponse(\PHPExcel_Writer_IWriter $writer, $status = 200, $headers = array()) | ||
{ | ||
return new StreamedResponse( | ||
function () use ($writer) { | ||
$writer->save('php://output'); | ||
}, | ||
$status, | ||
$headers | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,6 @@ | ||
parameters: | ||
xls.phpexcel.class: PHPExcel | ||
xls.service.class: Liuggio\ExcelBundle\Service\ExcelContainer | ||
phpexcel.class: Liuggio\ExcelBundle\Factory | ||
|
||
services: | ||
xls.phpexcel: | ||
class: %xls.phpexcel.class% | ||
|
||
xls.service: | ||
class: Liuggio\ExcelBundle\Service\Excel | ||
arguments: ["@xls.phpexcel"] | ||
|
||
xls.excel5: | ||
class: Liuggio\ExcelBundle\Service\Excel | ||
arguments: ["@xls.phpexcel" ] | ||
calls: | ||
- [ setType, [ "Excel5" ] ] | ||
|
||
xls.excel2007: | ||
class: Liuggio\ExcelBundle\Service\Excel | ||
arguments: ["@xls.phpexcel"] | ||
calls: | ||
- [ setType, [ "Excel2007" ] ] | ||
phpexcel: | ||
class: %phpexcel.class% |
Oops, something went wrong.