# tablepress/3.4/libraries/vendor/PhpSpreadsheet/Worksheet/AutoFit.php

TablePress – Tables in WordPress made easy, version 3.4. 50 lines.

- Page: https://pluginprobe.com/plugins/tablepress/3.4/code/libraries/vendor/PhpSpreadsheet/Worksheet/AutoFit.php
- Raw: https://pluginprobe.com/plugins/tablepress/3.4/raw/libraries/vendor/PhpSpreadsheet/Worksheet/AutoFit.php
- Modified: 2025-08-26T04:06:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/tablepress/3.4/code/libraries/vendor/PhpSpreadsheet/Worksheet/AutoFit.php#L10-L20`.

```php
<?php

namespace TablePress\PhpOffice\PhpSpreadsheet\Worksheet;

use TablePress\PhpOffice\PhpSpreadsheet\Cell\CellAddress;
use TablePress\PhpOffice\PhpSpreadsheet\Cell\CellRange;
use TablePress\PhpOffice\PhpSpreadsheet\Cell\Coordinate;

class AutoFit
{
	protected Worksheet $worksheet;

	public function __construct(Worksheet $worksheet)
	{
		$this->worksheet = $worksheet;
	}

	/** @return mixed[] */
	public function getAutoFilterIndentRanges(): array
	{
		$autoFilterIndentRanges = [];
		$autoFilterIndentRanges[] = $this->getAutoFilterIndentRange($this->worksheet->getAutoFilter());

		foreach ($this->worksheet->getTableCollection() as $table) {
			if ($table->getShowHeaderRow() === true && $table->getAllowFilter() === true) {
				$autoFilter = $table->getAutoFilter();
				$autoFilterIndentRanges[] = $this->getAutoFilterIndentRange($autoFilter);
			}
		}

		return array_filter($autoFilterIndentRanges);
	}

	private function getAutoFilterIndentRange(AutoFilter $autoFilter): ?string
	{
		$autoFilterRange = $autoFilter->getRange();
		$autoFilterIndentRange = null;

		if (!empty($autoFilterRange)) {
			$autoFilterRangeBoundaries = Coordinate::rangeBoundaries($autoFilterRange);
			$autoFilterIndentRange = (string) new CellRange(
				CellAddress::fromColumnAndRow($autoFilterRangeBoundaries[0][0], $autoFilterRangeBoundaries[0][1]),
				CellAddress::fromColumnAndRow($autoFilterRangeBoundaries[1][0], $autoFilterRangeBoundaries[0][1])
			);
		}

		return $autoFilterIndentRange;
	}
}

```
