Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/PhpSpreadsheet/Worksheet/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -3286,9 +3286,9 @@ public function toArray(
$this->garbageCollect();
$this->calculateArrays($calculateFormulas);

// Identify the range that we need to extract from the worksheet
$maxCol = $this->getHighestColumn();
$maxRow = $this->getHighestRow();
// Identify the range that we need to extract from the worksheet
$maxCol = $this->getHighestDataColumn();
$maxRow = $this->getHighestDataRow();

// Return
return $this->rangeToArray("A1:{$maxCol}{$maxRow}", $nullValue, $calculateFormulas, $formatData, $returnCellRef, $ignoreHidden, $reduceArrays);
Expand Down
5 changes: 2 additions & 3 deletions tests/PhpSpreadsheetTests/Reader/Xlsx/XlsxTest.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

declare(strict_types=1);
Expand All @@ -11,7 +11,6 @@
use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Style\Conditional;
use PhpOffice\PhpSpreadsheet\Style\Style;
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -194,11 +193,11 @@
$reader = new Xlsx();
$reader->setReadFilter(new OddColumnReadFilter());
$spreadsheet = $reader->load($filename);
$data = $spreadsheet->getActiveSheet()->toArray();
$data = $spreadsheet->getActiveSheet()->rangeToArray("A1:J10");
$ref = [1.0, null, 3.0, null, 5.0, null, 7.0, null, 9.0, null];

for ($i = 0; $i < 10; ++$i) {
self::assertEquals($ref, \array_slice($data[$i], 0, 10, true));
self::assertEquals($ref, $data[$i]);
}
$spreadsheet->disconnectWorksheets();
}
Expand Down
16 changes: 16 additions & 0 deletions tests/PhpSpreadsheetTests/Worksheet/ToArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,20 @@ public static function testMaxCol(): void
self::assertSame('start', $array[0][0]);
self::assertSame('end', $array[0][16383]);
}

public static function testToArrayConsidersValuesButNotFormatting(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();

$sheet->getCell('A1')->setValue('hello');
$array = $sheet->toArray(null, false, false, false, false);
self::assertSame([['hello']], $array);

// Create column dimension object that didn't exist yet
$sheet->getColumnDimension('C');
$array = $sheet->toArray(null, false, false, false, false);
// Yet there should be no column C in the export
self::assertSame([['hello']], $array);
}
}
Loading