Skip to content

Commit

Permalink
Merge pull request #227 from ThaDafinser/feature/excel-format
Browse files Browse the repository at this point in the history
better excel format
  • Loading branch information
ThaDafinser committed Feb 25, 2016
2 parents 4e2bc66 + 841684d commit a3357c8
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 9 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ matrix:
# faster builds on new travis setup not using sudo
sudo: false

cache:
directories:
- vendor

before_script:
- composer self-update
- composer update --prefer-source -n --verbose
Expand Down
1 change: 1 addition & 0 deletions src/ZfcDatagrid/Column/Style/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* general or based on a value
*
*/

namespace ZfcDatagrid\Column\Style;

class Color extends AbstractColor
Expand Down
1 change: 1 addition & 0 deletions src/ZfcDatagrid/Column/Type/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/**
* Image type
*/

namespace ZfcDatagrid\Column\Type;

use InvalidArgumentException;
Expand Down
1 change: 1 addition & 0 deletions src/ZfcDatagrid/DataSource/Doctrine2/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* or if we use the "safe" variant by Doctrine2
*
*/

namespace ZfcDatagrid\DataSource\Doctrine2;

use Doctrine\ORM\QueryBuilder;
Expand Down
6 changes: 4 additions & 2 deletions src/ZfcDatagrid/PrepareData.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ public function prepare()
/*
* Type converting
*/
$row[$col->getUniqueId()] = $col->getType()->getUserValue($row[$col->getUniqueId()]);
if ($this->getRendererName() != 'PHPExcel') {
$row[$col->getUniqueId()] = $col->getType()->getUserValue($row[$col->getUniqueId()]);
}

/*
* Translate (nach typ convertierung -> PhpArray...)
Expand All @@ -221,7 +223,7 @@ public function prepare()
array_walk_recursive($row[$col->getUniqueId()], function (&$value) {
$value = trim($value);
});
} else {
} elseif (!is_object($row[$col->getUniqueId()])) {
$row[$col->getUniqueId()] = trim($row[$col->getUniqueId()]);
}

Expand Down
1 change: 1 addition & 0 deletions src/ZfcDatagrid/Renderer/AbstractExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Methods which can be used in (all) export renderer
*
*/

namespace ZfcDatagrid\Renderer;

use ZfcDatagrid\Column;
Expand Down
4 changes: 2 additions & 2 deletions src/ZfcDatagrid/Renderer/Csv/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public function execute()

$fp = fopen($path . '/' . $saveFilename, 'w');
// Force UTF-8 for CSV rendering in EXCEL.
fprintf($fp, chr(0xEF).chr(0xBB).chr(0xBF));
fprintf($fp, chr(0xEF) . chr(0xBB) . chr(0xBF));

/*
* Save the file
*/
Expand Down
26 changes: 25 additions & 1 deletion src/ZfcDatagrid/Renderer/PHPExcel/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,38 @@ public function execute()
foreach ($this->getData() as $row) {
$xColumn = 0;
foreach ($this->getColumnsToExport() as $col) {
/* @var $col \ZfcDatagrid\Column\AbstractColumn */

$value = $row[$col->getUniqueId()];
if (is_array($value)) {
$value = implode(PHP_EOL, $value);
}

/* @var $column \ZfcDatagrid\Column\AbstractColumn */
$currentColumn = PHPExcel_Cell::stringFromColumnIndex($xColumn);
$sheet->getCell($currentColumn . $yRow)->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING);
$cell = $sheet->getCell($currentColumn . $yRow);

switch (get_class($col->getType())) {

case 'ZfcDatagrid\Column\Type\Number':
$cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_NUMERIC);
break;

case 'ZfcDatagrid\Column\Type\DateTime':
if ($value instanceof \DateTime) {
$value->setTimezone(new \DateTimeZone($col->getType()
->getOutputTimezone()));
}
$cell->setValue(\PHPExcel_Shared_Date::PHPToExcel($value));
$cell->getStyle()
->getNumberFormat()
->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME);
break;

default:
$cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING);
break;
}

$columnStyle = $sheet->getStyle($currentColumn . $yRow);
$columnStyle->getAlignment()->setWrapText(true);
Expand Down

0 comments on commit a3357c8

Please sign in to comment.