Merge branch 'master' into update_doc_number_format
This commit is contained in:
commit
263bbd5182
@ -56,12 +56,25 @@ class RowManager
|
|||||||
$rowCells = $row->getCells();
|
$rowCells = $row->getCells();
|
||||||
$maxCellIndex = $numCells;
|
$maxCellIndex = $numCells;
|
||||||
|
|
||||||
|
// If the row has empty cells, calling "setCellAtIndex" will add the cell
|
||||||
|
// but in the wrong place (the new cell is added at the end of the array).
|
||||||
|
// Therefore, we need to sort the array using keys to have proper order.
|
||||||
|
// @see https://github.com/box/spout/issues/740
|
||||||
|
$needsSorting = false;
|
||||||
|
|
||||||
for ($cellIndex = 0; $cellIndex < $maxCellIndex; $cellIndex++) {
|
for ($cellIndex = 0; $cellIndex < $maxCellIndex; $cellIndex++) {
|
||||||
if (!isset($rowCells[$cellIndex])) {
|
if (!isset($rowCells[$cellIndex])) {
|
||||||
$row->setCellAtIndex($this->entityFactory->createCell(''), $cellIndex);
|
$row->setCellAtIndex($this->entityFactory->createCell(''), $cellIndex);
|
||||||
|
$needsSorting = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($needsSorting) {
|
||||||
|
$rowCells = $row->getCells();
|
||||||
|
ksort($rowCells);
|
||||||
|
$row->setCells($rowCells);
|
||||||
|
}
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -692,13 +692,29 @@ class ReaderTest extends TestCase
|
|||||||
$allRows = $this->getAllRowsForFile('sheet_with_empty_cells.xlsx');
|
$allRows = $this->getAllRowsForFile('sheet_with_empty_cells.xlsx');
|
||||||
|
|
||||||
$expectedRows = [
|
$expectedRows = [
|
||||||
['A', 'B', 'C'],
|
['A', '', 'C'],
|
||||||
['0', '', ''],
|
['0', '', ''],
|
||||||
['1', '1', ''],
|
['1', '1', ''],
|
||||||
];
|
];
|
||||||
$this->assertEquals($expectedRows, $allRows, 'There should be 3 rows, with equal length');
|
$this->assertEquals($expectedRows, $allRows, 'There should be 3 rows, with equal length');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://github.com/box/spout/issues/184
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testReadShouldCreateOutputEmptyCellPreservedWhenNoDimensionsSpecified()
|
||||||
|
{
|
||||||
|
$allRows = $this->getAllRowsForFile('sheet_with_empty_cells_without_dimensions.xlsx');
|
||||||
|
|
||||||
|
$expectedRows = [
|
||||||
|
['A', '', 'C'],
|
||||||
|
['0'],
|
||||||
|
['1', '1'],
|
||||||
|
];
|
||||||
|
$this->assertEquals($expectedRows, $allRows);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://github.com/box/spout/issues/195
|
* https://github.com/box/spout/issues/195
|
||||||
* @return void
|
* @return void
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user