Skip to content

Commit

Permalink
fixing excel width
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaDafinser committed Nov 23, 2015
1 parent 7108df2 commit 8273aa3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
3 changes: 1 addition & 2 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php

$finder = Symfony\CS\Finder\DefaultFinder::create();
$finder->exclude('somedir');
$finder->in([
__DIR__ . '/config',
__DIR__ . '/src',
__DIR__ . '/tests'
]);
Expand Down
28 changes: 19 additions & 9 deletions src/ZfcDatagrid/Renderer/PHPExcel/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,15 @@ public function execute()
->setSize(15);
}

$this->calculateColumnWidth($this->getColumnsToExport());
/*
* Print settings
*/
$this->setPrinting($phpExcel);

/*
* Calculate column width
*/
$this->calculateColumnWidth($sheet, $this->getColumnsToExport());

/*
* Header
Expand Down Expand Up @@ -214,11 +222,6 @@ public function execute()
],
]);

/*
* Print settings
*/
$this->setPrinting($phpExcel);

/*
* Save the file
*/
Expand Down Expand Up @@ -257,15 +260,22 @@ public function execute()
/**
* Calculates the column width, based on the papersize and orientation
*
* @param array $columns
* @param PHPExcel_Worksheet $sheet
* @param array $columns
*/
protected function calculateColumnWidth(array $columns)
protected function calculateColumnWidth(PHPExcel_Worksheet $sheet, array $columns)
{
// First make sure the columns width is 100 "percent"
$this->calculateColumnWidthPercent($columns);

// width is in mm
$paperWidth = $this->getPaperWidth();
$paperWidth /= 2.19;

// remove margins (they are in inches!)
$paperWidth -= $sheet->getPageMargins()->getLeft() / 0.0393700787402;
$paperWidth -= $sheet->getPageMargins()->getRight() / 0.0393700787402;

$paperWidth /= 2;

$factor = $paperWidth / 100;
foreach ($columns as $column) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

namespace ZfcDatagridTest\DataSource\Doctrine2\Mocks;

/**
Expand Down

0 comments on commit 8273aa3

Please sign in to comment.