1 <?php 2 3 namespace PhpOffice\PhpSpreadsheet\Worksheet; 4 5 use PhpOffice\PhpSpreadsheet\Cell\CellAddress; 6 use PhpOffice\PhpSpreadsheet\Cell\CellRange; 7 use PhpOffice\PhpSpreadsheet\Cell\Coordinate; 8 9 class AutoFit 10 { 11 protected Worksheet $worksheet; 12 13 public function __construct(Worksheet $worksheet) 14 { 15 $this->worksheet = $worksheet; 16 } 17 18 public function getAutoFilterIndentRanges(): array 19 { 20 $autoFilterIndentRanges = []; 21 $autoFilterIndentRanges[] = $this->getAutoFilterIndentRange($this->worksheet->getAutoFilter()); 22 23 foreach ($this->worksheet->getTableCollection() as $table) { 24 /** @var Table $table */ 25 if ($table->getShowHeaderRow() === true && $table->getAllowFilter() === true) { 26 $autoFilter = $table->getAutoFilter(); 27 if ($autoFilter !== null) { 28 $autoFilterIndentRanges[] = $this->getAutoFilterIndentRange($autoFilter); 29 } 30 } 31 } 32 33 return array_filter($autoFilterIndentRanges); 34 } 35 36 private function getAutoFilterIndentRange(AutoFilter $autoFilter): ?string 37 { 38 $autoFilterRange = $autoFilter->getRange(); 39 $autoFilterIndentRange = null; 40 41 if (!empty($autoFilterRange)) { 42 $autoFilterRangeBoundaries = Coordinate::rangeBoundaries($autoFilterRange); 43 $autoFilterIndentRange = (string) new CellRange( 44 CellAddress::fromColumnAndRow($autoFilterRangeBoundaries[0][0], $autoFilterRangeBoundaries[0][1]), 45 CellAddress::fromColumnAndRow($autoFilterRangeBoundaries[1][0], $autoFilterRangeBoundaries[0][1]) 46 ); 47 } 48 49 return $autoFilterIndentRange; 50 } 51 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body