RowDimension.php 2.5 KB

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