Skip to content

Commit

Permalink
Umstellung auf Multipager Funktionalität
Browse files Browse the repository at this point in the history
  • Loading branch information
markus schnieder committed Nov 27, 2018
1 parent e3c0b6b commit 2f6ef19
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
53 changes: 50 additions & 3 deletions src/PhpSpreadsheet/TemplateFiller/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace PhpOffice\PhpSpreadsheet\TemplateFiller;

use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Shared\Drawing;
use PhpOffice\PhpSpreadsheet\Shared\Font;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;

class Table
Expand Down Expand Up @@ -110,16 +113,60 @@ public static function addImage(&$worksheet, $img, $h, $v, $width = 163, $height

public static function addImageToCell(Worksheet &$worksheet, $cellCoord, $img, $width = 163, $height = 30)
{
$cell = $worksheet->getCell($cellCoord);
$cell->setValue('');
// $cell = $worksheet->getCell($cellCoord);
$a = $worksheet->getMergeCells();

$width2 = 0;
$height2 = 0;
foreach($a as $key => $val) {
$widthrow = 0;
$lastcol = 0;
if(substr($key, 0, strlen($cellCoord)) == $cellCoord) {
$tmp = Coordinate::extractAllCellReferencesInRange($key);
foreach($tmp as $key => $coord) {
$cords = $worksheet->getCell($coord);
if($widthrow == 0) {
$widthrow = $cords->getRow();
}
$aktuelcol = $cords->getColumn();
if($lastcol === 0 || $lastcol === $aktuelcol) {
$po = $cords->getRow();
$tmpheight = $worksheet->getRowDimension($po)->getRowHeight();
if($tmpheight == -1) {
$font = $worksheet->getParent()->getDefaultStyle()->getFont();
$pointRowHeight = Font::getDefaultRowHeightByFont($font);
$tmpheight = $pointRowHeight;
} else {
$tmpheight = Drawing::pointsToPixels($tmpheight);
}
$height2 += $tmpheight;
$lastcol = $aktuelcol;
}
$co = $cords->getColumn();
if ($widthrow == $cords->getRow())
$width2 += $worksheet->getColumnDimension($co)->getWidth();
}
}
}

$width = $width2 * 7.8138144947537;
$height = $height2;
// $height = $height2 * 7.8138144947537;

$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing();
$drawing->setName('In-Memory Drawing 2');
$drawing->setCoordinates($cellCoord);

$drawing->setImageResource($img);
$drawing->setRenderingFunction(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_PNG);
$drawing->setMimeType(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::MIMETYPE_DEFAULT);
$drawing->setWidth($width);
$drawing->setHeight($height);
$drawing->setWidthAndHeight($width, $height);

if($height < Drawing::pointsToPixels($drawing->getHeight())) {
$drawing->setHeight($height);
}


$drawing->setWorksheet($worksheet);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/TemplateFiller/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private function fillData($d)
}
$cellValue = $d[$varName];
if (gettype($cellValue) == 'resource') {
Table::addImageToCell($this->worksheet, $coord, $cellValue, 163, 30);
Table::addImageToCell($this->worksheet, $coord, $cellValue);
} else {
$value = str_replace($val['matches'][$i], $cellValue, $value);
$this->worksheet->getCell($coord)->setValue($value);
Expand Down

0 comments on commit 2f6ef19

Please sign in to comment.