See Release Notes
Long Term Support Release
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 class Row 6 { 7 /** 8 * \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet. 9 * 10 * @var Worksheet 11 */ 12 private $worksheet; 13 14 /** 15 * Row index. 16 * 17 * @var int 18 */ 19 private $rowIndex = 0; 20 21 /** 22 * Create a new row. 23 * 24 * @param int $rowIndex 25 */ 26 public function __construct(Worksheet $worksheet, $rowIndex = 1) 27 { 28 // Set parent and row index 29 $this->worksheet = $worksheet; 30 $this->rowIndex = $rowIndex; 31 } 32 33 /** 34 * Destructor. 35 */ 36 public function __destruct() 37 { 38 $this->worksheet = null; // @phpstan-ignore-line 39 } 40 41 /** 42 * Get row index. 43 */ 44 public function getRowIndex(): int 45 { 46 return $this->rowIndex; 47 } 48 49 /** 50 * Get cell iterator. 51 * 52 * @param string $startColumn The column address at which to start iterating 53 * @param string $endColumn Optionally, the column address at which to stop iterating 54 * 55 * @return RowCellIterator 56 */ 57 public function getCellIterator($startColumn = 'A', $endColumn = null) 58 { 59 return new RowCellIterator($this->worksheet, $this->rowIndex, $startColumn, $endColumn); 60 } 61 62 /** 63 * Returns a boolean true if the row contains no cells. By default, this means that no cell records exist in the 64 * collection for this row. false will be returned otherwise. 65 * This rule can be modified by passing a $definitionOfEmptyFlags value: 66 * 1 - CellIterator::TREAT_NULL_VALUE_AS_EMPTY_CELL If the only cells in the collection are null value 67 * cells, then the row will be considered empty. 68 * 2 - CellIterator::TREAT_EMPTY_STRING_AS_EMPTY_CELL If the only cells in the collection are empty 69 * string value cells, then the row will be considered empty. 70 * 3 - CellIterator::TREAT_NULL_VALUE_AS_EMPTY_CELL | CellIterator::TREAT_EMPTY_STRING_AS_EMPTY_CELL 71 * If the only cells in the collection are null value or empty string value cells, then the row 72 * will be considered empty. 73 * 74 * @param int $definitionOfEmptyFlags 75 * Possible Flag Values are: 76 * CellIterator::TREAT_NULL_VALUE_AS_EMPTY_CELL 77 * CellIterator::TREAT_EMPTY_STRING_AS_EMPTY_CELL 78 */ 79 public function isEmpty(int $definitionOfEmptyFlags = 0): bool 80 { 81 $nullValueCellIsEmpty = (bool) ($definitionOfEmptyFlags & CellIterator::TREAT_NULL_VALUE_AS_EMPTY_CELL); 82 $emptyStringCellIsEmpty = (bool) ($definitionOfEmptyFlags & CellIterator::TREAT_EMPTY_STRING_AS_EMPTY_CELL); 83 84 $cellIterator = $this->getCellIterator(); 85 $cellIterator->setIterateOnlyExistingCells(true); 86 foreach ($cellIterator as $cell) { 87 $value = $cell->getValue(); 88 if ($value === null && $nullValueCellIsEmpty === true) { 89 continue; 90 } 91 if ($value === '' && $emptyStringCellIsEmpty === true) { 92 continue; 93 } 94 95 return false; 96 } 97 98 return true; 99 } 100 101 /** 102 * Returns bound worksheet. 103 */ 104 public function getWorksheet(): Worksheet 105 { 106 return $this->worksheet; 107 } 108 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body