Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4505,26 +4505,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Style/NumberFormat/PercentageFormatter.php

-
message: "#^Cannot call method getCell\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#"
count: 1
path: src/PhpSpreadsheet/Worksheet/BaseDrawing.php

-
message: "#^Cannot call method getDrawingCollection\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#"
count: 1
path: src/PhpSpreadsheet/Worksheet/BaseDrawing.php

-
message: "#^Cannot call method getHashCode\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#"
count: 1
path: src/PhpSpreadsheet/Worksheet/BaseDrawing.php

-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\BaseDrawing\\:\\:\\$shadow \\(PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Drawing\\\\Shadow\\) does not accept PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Drawing\\\\Shadow\\|null\\.$#"
count: 1
path: src/PhpSpreadsheet/Worksheet/BaseDrawing.php

-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\CellIterator\\:\\:adjustForExistingOnlyRange\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -5600,31 +5580,6 @@ parameters:
count: 2
path: src/PhpSpreadsheet/Writer/Xlsx/DocProps.php

-
message: "#^Parameter \\#1 \\$index of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\:\\:getChartByIndex\\(\\) expects string, int\\<0, max\\> given\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Xlsx/Drawing.php

-
message: "#^Parameter \\#2 \\$chart of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xlsx\\\\Drawing\\:\\:writeChart\\(\\) expects PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart, PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\|false given\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Xlsx/Drawing.php

-
message: "#^Parameter \\#2 \\$content of method XMLWriter\\:\\:writeElement\\(\\) expects string\\|null, int given\\.$#"
count: 12
path: src/PhpSpreadsheet/Writer/Xlsx/Drawing.php

-
message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, int given\\.$#"
count: 8
path: src/PhpSpreadsheet/Writer/Xlsx/Drawing.php

-
message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, int\\<0, max\\> given\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Xlsx/Drawing.php

-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xlsx\\\\Rels\\:\\:writeUnparsedRelationship\\(\\) has parameter \\$relationship with no type specified\\.$#"
count: 1
Expand Down
78 changes: 78 additions & 0 deletions samples/Basic/48_Image_move_size_with_cells.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

// Create new Spreadsheet object
use PhpOffice\PhpSpreadsheet\Helper\Dimension;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;

require __DIR__ . '/../Header.php';

$helper->log('Create new Spreadsheet object');
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue('twocell');
$sheet->getCell('A2')->setValue('twocell');
$sheet->getCell('A3')->setValue('onecell');
$sheet->getCell('A6')->setValue('absolute');

// Add a drawing to the worksheet
$helper->log('Add a drawing to the worksheet two-cell anchor not resized');
$drawing = new Drawing();
$drawing->setName('PhpSpreadsheet');
$drawing->setDescription('PhpSpreadsheet');
$drawing->setPath(__DIR__ . '/../images/PhpSpreadsheet_logo.png');
// anchor type will be two-cell because Coordinates2 is set
//$drawing->setAnchorType(Drawing::ANCHORTYPE_TWOCELL);
$drawing->setCoordinates('B1');
$drawing->setCoordinates2('B1');
$drawing->setOffsetX2($drawing->getImageWidth());
$drawing->setOffsetY2($drawing->getImageHeight());
$drawing->setWorksheet($spreadsheet->getActiveSheet());

// Add a drawing to the worksheet
$helper->log('Add a drawing to the worksheet two-cell anchor resized');
$drawing2 = new Drawing();
$drawing2->setName('PhpSpreadsheet');
$drawing2->setDescription('PhpSpreadsheet');
$drawing2->setPath(__DIR__ . '/../images/PhpSpreadsheet_logo.png');
// anchor type will be two-cell because Coordinates2 is set
//$drawing->setAnchorType(Drawing::ANCHORTYPE_TWOCELL);
$drawing2->setCoordinates('C2');
$drawing2->setCoordinates2('C2');
$drawing2->setOffsetX2($drawing->getImageWidth());
$drawing2->setOffsetY2($drawing->getImageHeight());
$drawing2->setWorksheet($spreadsheet->getActiveSheet());

$spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth($drawing->getImageWidth(), Dimension::UOM_PIXELS);
$spreadsheet->getActiveSheet()->getRowDimension(2)->setRowHeight($drawing->getImageHeight(), Dimension::UOM_PIXELS);

// Add a drawing to the worksheet one cell anchor
$helper->log('Add a drawing to the worksheet one-cell anchor');
$drawing3 = new Drawing();
$drawing3->setName('PhpSpreadsheet');
$drawing3->setDescription('PhpSpreadsheet');
$drawing3->setPath(__DIR__ . '/../images/PhpSpreadsheet_logo.png');
// anchor type will be one-cell because Coordinates2 is not set
//$drawing->setAnchorType(Drawing::ANCHORTYPE_ONECELL);
$drawing3->setCoordinates('D3');
$drawing3->setWorksheet($spreadsheet->getActiveSheet());

// Add a drawing to the worksheet
$helper->log('Add a drawing to the worksheet two-cell anchor resized absolute');
$drawing4 = new Drawing();
$drawing4->setName('PhpSpreadsheet');
$drawing4->setDescription('PhpSpreadsheet');
$drawing4->setPath(__DIR__ . '/../images/PhpSpreadsheet_logo.png');
// anchor type will be two-cell because Coordinates2 is set
//$drawing->setAnchorType(Drawing::ANCHORTYPE_TWOCELL);
$drawing4->setCoordinates('C6');
$drawing4->setCoordinates2('C6');
$drawing4->setOffsetX2($drawing->getImageWidth());
$drawing4->setOffsetY2($drawing->getImageHeight());
$drawing4->setWorksheet($spreadsheet->getActiveSheet());
$drawing4->setEditAs(Drawing::EDIT_AS_ABSOLUTE);

//$spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth($drawing->getImageWidth(), Dimension::UOM_PIXELS);
$spreadsheet->getActiveSheet()->getRowDimension(6)->setRowHeight($drawing->getImageHeight(), Dimension::UOM_PIXELS);

$helper->write($spreadsheet, __FILE__, ['Xlsx']);
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Calculation/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public static function isEven($value = null)
return self::VALUE();
}

return $value % 2 == 0;
return (int) fmod($value, 2.0) === 0;
}

/**
Expand All @@ -421,7 +421,7 @@ public static function isOdd($value = null)
return self::VALUE();
}

return abs($value) % 2 == 1;
return (int) fmod($value, 2.0) !== 0;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/PhpSpreadsheet/Cell/Coordinate.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public static function absoluteReference($cellAddress)
}

// Create absolute coordinate
$cellAddress = "$cellAddress";
if (ctype_digit($cellAddress)) {
return $worksheet . '$' . $cellAddress;
} elseif (ctype_alpha($cellAddress)) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Helper/Dimension.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Dimension
public function __construct(string $dimension)
{
[$size, $unit] = sscanf($dimension, '%[1234567890.]%s');
$unit = strtolower(trim($unit));
$unit = strtolower(trim($unit ?? ''));

// If a UoM is specified, then convert the size to pixels for internal storage
if (isset(self::ABSOLUTE_UNITS[$unit])) {
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Reader/Xls.php
Original file line number Diff line number Diff line change
Expand Up @@ -1105,8 +1105,8 @@ public function load(string $filename, int $flags = 0)
$height = SharedXls::getDistanceY($this->phpSheet, $startRow, $startOffsetY, $endRow, $endOffsetY);

// calculate offsetX and offsetY of the shape
$offsetX = $startOffsetX * SharedXls::sizeCol($this->phpSheet, $startColumn) / 1024;
$offsetY = $startOffsetY * SharedXls::sizeRow($this->phpSheet, $startRow) / 256;
$offsetX = (int) ($startOffsetX * SharedXls::sizeCol($this->phpSheet, $startColumn) / 1024);
$offsetY = (int) ($startOffsetY * SharedXls::sizeRow($this->phpSheet, $startRow) / 256);

switch ($obj['otObjType']) {
case 0x19:
Expand Down
8 changes: 8 additions & 0 deletions src/PhpSpreadsheet/Reader/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,10 @@ public function load(string $filename, int $flags = 0): Spreadsheet
$outerShdw = $twoCellAnchor->pic->spPr->children(Namespaces::DRAWINGML)->effectLst->outerShdw;
$hlinkClick = $twoCellAnchor->pic->nvPicPr->cNvPr->children(Namespaces::DRAWINGML)->hlinkClick;
$objDrawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$editAs = $twoCellAnchor->attributes();
if (isset($editAs, $editAs['editAs'])) {
$objDrawing->setEditAs($editAs['editAs']);
}
$objDrawing->setName((string) self::getArrayItem(self::getAttributes($twoCellAnchor->pic->nvPicPr->cNvPr), 'name'));
$objDrawing->setDescription((string) self::getArrayItem(self::getAttributes($twoCellAnchor->pic->nvPicPr->cNvPr), 'descr'));
$embedImageKey = (string) self::getArrayItem(
Expand All @@ -1339,6 +1343,10 @@ public function load(string $filename, int $flags = 0): Spreadsheet

$objDrawing->setOffsetX(Drawing::EMUToPixels($twoCellAnchor->from->colOff));
$objDrawing->setOffsetY(Drawing::EMUToPixels($twoCellAnchor->from->rowOff));
$objDrawing->setCoordinates2(Coordinate::stringFromColumnIndex(((int) $twoCellAnchor->to->col) + 1) . ($twoCellAnchor->to->row + 1));

$objDrawing->setOffsetX2(Drawing::EMUToPixels($twoCellAnchor->to->colOff));
$objDrawing->setOffsetY2(Drawing::EMUToPixels($twoCellAnchor->to->rowOff));
$objDrawing->setResizeProportional(false);

if ($xfrm) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Worksheet/AutoFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ private static function filterTestInCustomDataSet($cellValue, $ruleSet)
/** @var string */
$ruleOperator = $rule['operator'];
/** @var string */
$cellValueString = $cellValue;
$cellValueString = $cellValue ?? '';
$retVal = false;

if (is_numeric($ruleValue)) {
Expand Down
Loading