Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Worksheet;
   4  
   5  use PhpOffice\PhpSpreadsheet\Helper\Dimension as CssDimension;
   6  
   7  class RowDimension extends Dimension
   8  {
   9      /**
  10       * Row index.
  11       *
  12       * @var int
  13       */
  14      private $rowIndex;
  15  
  16      /**
  17       * Row height (in pt).
  18       *
  19       * When this is set to a negative value, the row height should be ignored by IWriter
  20       *
  21       * @var float
  22       */
  23      private $height = -1;
  24  
  25      /**
  26       * ZeroHeight for Row?
  27       *
  28       * @var bool
  29       */
  30      private $zeroHeight = false;
  31  
  32      /**
  33       * Create a new RowDimension.
  34       *
  35       * @param int $index Numeric row index
  36       */
  37      public function __construct($index = 0)
  38      {
  39          // Initialise values
  40          $this->rowIndex = $index;
  41  
  42          // set dimension as unformatted by default
  43          parent::__construct(null);
  44      }
  45  
  46      /**
  47       * Get Row Index.
  48       */
  49      public function getRowIndex(): int
  50      {
  51          return $this->rowIndex;
  52      }
  53  
  54      /**
  55       * Set Row Index.
  56       *
  57       * @return $this
  58       */
  59      public function setRowIndex(int $index)
  60      {
  61          $this->rowIndex = $index;
  62  
  63          return $this;
  64      }
  65  
  66      /**
  67       * Get Row Height.
  68       * By default, this will be in points; but this method also accepts an optional unit of measure
  69       *    argument, and will convert the value from points to the specified UoM.
  70       *    A value of -1 tells Excel to display this column in its default height.
  71       *
  72       * @return float
  73       */
  74      public function getRowHeight(?string $unitOfMeasure = null)
  75      {
  76          return ($unitOfMeasure === null || $this->height < 0)
  77              ? $this->height
  78              : (new CssDimension($this->height . CssDimension::UOM_POINTS))->toUnit($unitOfMeasure);
  79      }
  80  
  81      /**
  82       * Set Row Height.
  83       *
  84       * @param float $height in points. A value of -1 tells Excel to display this column in its default height.
  85       * By default, this will be the passed argument value; but this method also accepts an optional unit of measure
  86       *    argument, and will convert the passed argument value to points from the specified UoM
  87       *
  88       * @return $this
  89       */
  90      public function setRowHeight($height, ?string $unitOfMeasure = null)
  91      {
  92          $this->height = ($unitOfMeasure === null || $height < 0)
  93              ? $height
  94              : (new CssDimension("{$height}{$unitOfMeasure}"))->height();
  95  
  96          return $this;
  97      }
  98  
  99      /**
 100       * Get ZeroHeight.
 101       */
 102      public function getZeroHeight(): bool
 103      {
 104          return $this->zeroHeight;
 105      }
 106  
 107      /**
 108       * Set ZeroHeight.
 109       *
 110       * @return $this
 111       */
 112      public function setZeroHeight(bool $zeroHeight)
 113      {
 114          $this->zeroHeight = $zeroHeight;
 115  
 116          return $this;
 117      }
 118  }