Skip to content

Commit e826625

Browse files
Add support for column ranges > Z (SpartnerNL#1636)
1 parent 9561acb commit e826625

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/Sheet.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Maatwebsite\Excel;
44

5+
use PhpOffice\PhpSpreadsheet\Cell\Cell;
6+
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
7+
use PhpOffice\PhpSpreadsheet\Collection\Cells;
58
use PhpOffice\PhpSpreadsheet\IOFactory;
69
use Maatwebsite\Excel\Concerns\FromView;
710
use Maatwebsite\Excel\Events\AfterSheet;
@@ -190,7 +193,7 @@ public function append(array $rows, int $row = null, bool $strictNullComparison
190193
*/
191194
public function autoSize()
192195
{
193-
foreach (range('A', $this->worksheet->getHighestDataColumn()) as $col) {
196+
foreach ($this->buildColumnRange('A', $this->worksheet->getHighestDataColumn()) as $col) {
194197
$this->worksheet->getColumnDimension($col)->setAutoSize(true);
195198
}
196199
}
@@ -268,6 +271,20 @@ protected function appendRow($row, $sheetExport)
268271
$this->append([$row], null, $this->hasStrictNullComparison($sheetExport));
269272
}
270273

274+
/**
275+
* @param string $lower
276+
* @param string $upper
277+
*
278+
* @return \Generator
279+
*/
280+
protected function buildColumnRange(string $lower, string $upper)
281+
{
282+
++$upper;
283+
for ($i = $lower; $i !== $upper; ++$i) {
284+
yield $i;
285+
}
286+
}
287+
271288
/**
272289
* @return string
273290
*/

0 commit comments

Comments
 (0)