Quantcast
Channel: PHPExcel Forum Rss Feed
Viewing all articles
Browse latest Browse all 2707

New Post: PHPExcel export xlsx with drawing got bug in width and height

$
0
0
This is helpfull patch for PHPExcel 1.8.0. The problem resolved in it:
diff -rub PHPExcel_1.8.0.orig/Classes/PHPExcel/Reader/Excel2007.php phpexcel/Classes/PHPExcel/Reader/Excel2007.php
--- PHPExcel_1.8.0.orig/Classes/PHPExcel/Reader/Excel2007.php   2015-04-21 18:14:03.542709000 +0400
+++ phpexcel/Classes/PHPExcel/Reader/Excel2007.php  2015-04-21 18:29:53.707014100 +0400
@@ -1502,10 +1502,20 @@
                                                    $objDrawing->setCoordinates(PHPExcel_Cell::stringFromColumnIndex((string) $twoCellAnchor->from->col) . ($twoCellAnchor->from->row + 1));
                                                    $objDrawing->setOffsetX(PHPExcel_Shared_Drawing::EMUToPixels($twoCellAnchor->from->colOff));
                                                    $objDrawing->setOffsetY(PHPExcel_Shared_Drawing::EMUToPixels($twoCellAnchor->from->rowOff));
+
+                                                   $objDrawing->setToCoordinates(PHPExcel_Cell::stringFromColumnIndex((string) $twoCellAnchor->to->col) . ($twoCellAnchor->to->row + 1));
+                                                   $objDrawing->setToOffsetX(PHPExcel_Shared_Drawing::EMUToPixels($twoCellAnchor->to->colOff));
+                                                   $objDrawing->setToOffsetY(PHPExcel_Shared_Drawing::EMUToPixels($twoCellAnchor->to->rowOff));
+
                                                    $objDrawing->setResizeProportional(false);
 
-                                                   $objDrawing->setWidth(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($xfrm->ext->attributes(), "cx")));
-                                                   $objDrawing->setHeight(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($xfrm->ext->attributes(), "cy")));
+//                                                 if ($xfrm->ext) {
+//                                                     $objDrawing->setWidth(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($xfrm->ext->attributes(), "cx")));
+//                                                     $objDrawing->setHeight(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($xfrm->ext->attributes(), "cy")));
+//                                                 }
+
+                                                   $objDrawing->setWidth(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($twoCellAnchor->ext->attributes(), "cx")));
+                                                   $objDrawing->setHeight(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($twoCellAnchor->ext->attributes(), "cy")));
 
                                                    if ($xfrm) {
                                                        $objDrawing->setRotation(PHPExcel_Shared_Drawing::angleToDegrees(self::array_item($xfrm->attributes(), "rot")));
diff -rub PHPExcel_1.8.0.orig/Classes/PHPExcel/Worksheet/BaseDrawing.php phpexcel/Classes/PHPExcel/Worksheet/BaseDrawing.php
--- PHPExcel_1.8.0.orig/Classes/PHPExcel/Worksheet/BaseDrawing.php  2015-04-21 18:14:04.212710000 +0400
+++ phpexcel/Classes/PHPExcel/Worksheet/BaseDrawing.php 2015-04-21 17:57:39.647282800 +0400
@@ -253,6 +253,22 @@
     }
 
     /**
+    * Coordinates
+    *
+    * @var string
+    */
+   private $_toCoordinates;
+
+    /**
+     * Get "TO" Coordinates
+     *
+     * @return string
+     */
+    public function getToCoordinates() {
+       return $this->_toCoordinates;
+    }
+
+    /**
      * Set Coordinates
      *
      * @param string $pValue
@@ -264,6 +280,17 @@
     }
 
     /**
+     * Set "TO" Coordinates
+     *
+     * @param string $pValue
+     * @return PHPExcel_Worksheet_BaseDrawing
+     */
+    public function setToCoordinates($pValue = 'A1') {
+       $this->_toCoordinates = $pValue;
+       return $this;
+    }
+
+    /**
      * Get OffsetX
      *
      * @return int
@@ -284,6 +311,47 @@
     }
 
     /**
+    * @var int
+    */
+   private $_toOffsetX;
+   /**
+    * @var int
+    */
+   private $_toOffsetY;
+
+    /**
+     * @return int
+     */
+    public function getToOffsetX() {
+       return $this->_toOffsetX;
+    }
+
+    /**
+     * @param int $pValue
+     * @return PHPExcel_Worksheet_BaseDrawing
+     */
+    public function setToOffsetX($pValue = 0) {
+       $this->_toOffsetX = $pValue;
+       return $this;
+    }
+
+    /**
+     * @return int
+     */
+    public function getToOffsetY() {
+       return $this->_toOffsetY;
+    }
+
+    /**
+     * @param int $pValue
+     * @return PHPExcel_Worksheet_BaseDrawing
+     */
+    public function setToOffsetY($pValue = 0) {
+       $this->_toOffsetY = $pValue;
+       return $this;
+    }
+
+    /**
      * Get OffsetY
      *
      * @return int
diff -rub PHPExcel_1.8.0.orig/Classes/PHPExcel/Writer/Excel2007/Drawing.php phpexcel/Classes/PHPExcel/Writer/Excel2007/Drawing.php
--- PHPExcel_1.8.0.orig/Classes/PHPExcel/Writer/Excel2007/Drawing.php   2015-04-21 18:14:04.392710200 +0400
+++ phpexcel/Classes/PHPExcel/Writer/Excel2007/Drawing.php  2015-04-21 20:02:13.711107600 +0400
@@ -172,6 +172,32 @@
    public function _writeDrawing(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet_BaseDrawing $pDrawing = null, $pRelationId = -1)
    {
        if ($pRelationId >= 0) {
+           if ($pDrawing->getToCoordinates()) {
+                $objWriter->startElement('xdr:twoCellAnchor');
+                // Image location
+                $aCoordinates         = PHPExcel_Cell::coordinateFromString($pDrawing->getCoordinates());
+                $aCoordinates[0]     = PHPExcel_Cell::columnIndexFromString($aCoordinates[0]);
+
+                $aCoordinatesTO         = PHPExcel_Cell::coordinateFromString($pDrawing->getToCoordinates());
+                $aCoordinatesTO[0]      = PHPExcel_Cell::columnIndexFromString($aCoordinatesTO[0]);
+
+                // xdr:from
+                $objWriter->startElement('xdr:from');
+                    $objWriter->writeElement('xdr:col', $aCoordinates[0] - 1);
+                    $objWriter->writeElement('xdr:colOff', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getOffsetX()));
+                    $objWriter->writeElement('xdr:row', $aCoordinates[1] - 1);
+                    $objWriter->writeElement('xdr:rowOff', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getOffsetY()));
+                $objWriter->endElement();
+
+                // xdr:to
+                $objWriter->startElement('xdr:to');
+                    $objWriter->writeElement('xdr:col', $aCoordinatesTO[0] - 1);
+                    $objWriter->writeElement('xdr:colOff', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getToOffsetX()));
+                    $objWriter->writeElement('xdr:row', $aCoordinatesTO[1] - 1);
+                    $objWriter->writeElement('xdr:rowOff', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getToOffsetY()));
+                $objWriter->endElement();
+           }
+           else {
            // xdr:oneCellAnchor
            $objWriter->startElement('xdr:oneCellAnchor');
                // Image location
@@ -191,6 +217,7 @@
                    $objWriter->writeAttribute('cx', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getWidth()));
                    $objWriter->writeAttribute('cy', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getHeight()));
                $objWriter->endElement();
+           }
 
                // xdr:pic
                $objWriter->startElement('xdr:pic');

Viewing all articles
Browse latest Browse all 2707

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>