mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 04:23:19 +00:00
PHRAS-2189 report v2 master (#2742)
move code to services added "download" report change services to factory added excel lib added prod/report routes (download) cleanup api routes add : allow anonymized (user, fonction, societe... are "-") removed : xls support (memory eating lib) in favor of xlsx add : report download only on "document" and "preview" subdef classes cs : report factory add : restored "site" filter (see todos in src) remove debug, cs todo : doc
This commit is contained in:
86
lib/Alchemy/Phrasea/Out/Module/Excel.php
Normal file
86
lib/Alchemy/Phrasea/Out/Module/Excel.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2016 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Out\Module;
|
||||
|
||||
use Box\Spout\Writer;
|
||||
use Box\Spout\Writer\WriterFactory;
|
||||
use Box\Spout\Common\Type;
|
||||
|
||||
|
||||
class Excel
|
||||
{
|
||||
const FORMAT_CSV = 'format_csv';
|
||||
const FORMAT_ODS = 'format_ods';
|
||||
const FORMAT_XLSX = 'format_xlsx';
|
||||
|
||||
private $format;
|
||||
|
||||
/** @var \Box\Spout\Writer\WriterInterface */
|
||||
private $writer;
|
||||
|
||||
|
||||
public function __construct($format, $filename)
|
||||
{
|
||||
$this->format = $format;
|
||||
|
||||
switch($format) {
|
||||
case self::FORMAT_CSV:
|
||||
/** @var Writer\CSV\Writer $writer */
|
||||
$writer = WriterFactory::create(Type::CSV);
|
||||
$writer->setFieldDelimiter(';')
|
||||
->setShouldAddBOM(false);
|
||||
break;
|
||||
case self::FORMAT_ODS:
|
||||
/** @var Writer\ODS\Writer $writer */
|
||||
$writer = WriterFactory::create(Type::ODS);
|
||||
break;
|
||||
case self::FORMAT_XLSX:
|
||||
/** @var Writer\XLSX\Writer $writer */
|
||||
$writer = WriterFactory::create(Type::XLSX);
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException(sprintf("format \"%s\" is not handled by Spout"));
|
||||
break;
|
||||
}
|
||||
|
||||
$writer->openToBrowser($filename);
|
||||
$this->writer = $writer;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->writer->close();
|
||||
}
|
||||
|
||||
public function getActiveSheet()
|
||||
{
|
||||
if($this->format == self::FORMAT_CSV) {
|
||||
return "_unique_sheet_";
|
||||
}
|
||||
/** @var Writer\XLSX\Writer $w */
|
||||
$w = $this->writer;
|
||||
$sheetIndex = $w->getCurrentSheet()->getIndex();
|
||||
|
||||
return $sheetIndex;
|
||||
}
|
||||
|
||||
public function addRow($row)
|
||||
{
|
||||
$this->writer->addRow($row);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$this->writer->close();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user