diff --git a/src/PhpSpreadsheet/Worksheet/BaseDrawing.php b/src/PhpSpreadsheet/Worksheet/BaseDrawing.php index 98b689729e..dcf42f9bf2 100644 --- a/src/PhpSpreadsheet/Worksheet/BaseDrawing.php +++ b/src/PhpSpreadsheet/Worksheet/BaseDrawing.php @@ -78,6 +78,13 @@ class BaseDrawing implements IComparable */ protected $height; + /** + * Move and resize type. + * + * @var string + */ + protected $resizeType = "oneCellAnchor"; + /** * Proportional resize. * @@ -431,7 +438,31 @@ public function setResizeProportional($pValue) return $this; } + + /** + * Get ResizeType. + * + * @return string + */ + public function getResizeType() + { + return $this->resizeType; + } + /** + * Set ResizeType. + * + * @param string $pValue + * + * @return BaseDrawing + */ + public function setResizeType($pValue) + { + $this->resizeType = $pValue; + + return $this; + } + /** * Get Rotation. * diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Drawing.php b/src/PhpSpreadsheet/Writer/Xlsx/Drawing.php index 08256a1d5b..164851cb7c 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Drawing.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Drawing.php @@ -162,8 +162,8 @@ public function writeChart(XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Chart public function writeDrawing(XMLWriter $objWriter, BaseDrawing $pDrawing, $pRelationId = -1, $hlinkClickId = null) { if ($pRelationId >= 0) { - // xdr:oneCellAnchor - $objWriter->startElement('xdr:oneCellAnchor'); + // xdr oneCell or twoCell Anchor + $objWriter->startElement('xdr:'.$pDrawing->getResizeType()); // Image location $aCoordinates = Coordinate::coordinateFromString($pDrawing->getCoordinates()); $aCoordinates[0] = Coordinate::columnIndexFromString($aCoordinates[0]); @@ -175,7 +175,17 @@ public function writeDrawing(XMLWriter $objWriter, BaseDrawing $pDrawing, $pRela $objWriter->writeElement('xdr:row', $aCoordinates[1] - 1); $objWriter->writeElement('xdr:rowOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->getOffsetY())); $objWriter->endElement(); - + + // xdr:to for twoCellAnchor + if($pDrawing->getResizeType()==='twoCellAnchor'){ + $objWriter->startElement('xdr:to'); + $objWriter->writeElement('xdr:col', $aCoordinates[0]); + $objWriter->writeElement('xdr:colOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->getOffsetX())); + $objWriter->writeElement('xdr:row', $aCoordinates[1]); + $objWriter->writeElement('xdr:rowOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->getOffsetY())); + $objWriter->endElement(); + } + // xdr:ext $objWriter->startElement('xdr:ext'); $objWriter->writeAttribute('cx', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->getWidth()));