Properly set selected cells for frozen panes
Properly set the selected cells for worksheets with frozen panes when writing Xlsx documents. Beforehand, the saved Xlsx documents were generating corruption warnings when opened in Excel. Fixes #532 Closes #535
This commit is contained in:
parent
e3fb160f5f
commit
4c09d4f668
|
@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||
- Make newer Excel versions properly recalculate formulas on document open - [#456](https://github.com/PHPOffice/PhpSpreadsheet/issues/456)
|
||||
- `Coordinate::extractAllCellReferencesInRange()` throws an exception for an invalid range – [#519](https://github.com/PHPOffice/PhpSpreadsheet/issues/519)
|
||||
- Fixed parsing of conditionals in COUNTIF functions - [#526](https://github.com/PHPOffice/PhpSpreadsheet/issues/526)
|
||||
- Corruption errors for saved Xlsx docs with frozen panes - [#532](https://github.com/PHPOffice/PhpSpreadsheet/issues/532)
|
||||
|
||||
## [1.2.1] - 2018-04-10
|
||||
|
||||
|
|
|
@ -246,6 +246,7 @@ class Worksheet extends WriterPart
|
|||
}
|
||||
|
||||
$activeCell = $pSheet->getActiveCell();
|
||||
$sqref = $pSheet->getSelectedCells();
|
||||
|
||||
// Pane
|
||||
$pane = '';
|
||||
|
@ -257,6 +258,7 @@ class Worksheet extends WriterPart
|
|||
|
||||
$topLeftCell = $pSheet->getTopLeftCell();
|
||||
$activeCell = $topLeftCell;
|
||||
$sqref = $topLeftCell;
|
||||
|
||||
// pane
|
||||
$pane = 'topRight';
|
||||
|
@ -292,7 +294,7 @@ class Worksheet extends WriterPart
|
|||
$objWriter->writeAttribute('pane', $pane);
|
||||
}
|
||||
$objWriter->writeAttribute('activeCell', $activeCell);
|
||||
$objWriter->writeAttribute('sqref', $pSheet->getSelectedCells());
|
||||
$objWriter->writeAttribute('sqref', $sqref);
|
||||
$objWriter->endElement();
|
||||
|
||||
$objWriter->endElement();
|
||||
|
|
|
@ -37,4 +37,39 @@ class FreezePaneTest extends AbstractFunctional
|
|||
self::assertSame($cellSplit, $actualCellSplit, 'should be able to set freeze pane');
|
||||
self::assertSame($topLeftCell, $actualTopLeftCell, 'should be able to set the top left cell');
|
||||
}
|
||||
|
||||
public function providerFormatsInvalidSelectedCells()
|
||||
{
|
||||
return [
|
||||
['Xlsx'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerFormatsInvalidSelectedCells
|
||||
*
|
||||
* @param string $format
|
||||
*/
|
||||
public function testFreezePaneWithInvalidSelectedCells($format)
|
||||
{
|
||||
$cellSplit = 'A7';
|
||||
$topLeftCell = 'A24';
|
||||
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$worksheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
$worksheet->freezePane('A7', 'A24');
|
||||
$worksheet->setSelectedCells('F5');
|
||||
|
||||
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format);
|
||||
|
||||
// Read written file
|
||||
$reloadedActive = $reloadedSpreadsheet->getActiveSheet();
|
||||
$actualCellSplit = $reloadedActive->getFreezePane();
|
||||
$actualTopLeftCell = $reloadedActive->getTopLeftCell();
|
||||
|
||||
self::assertSame($cellSplit, $actualCellSplit, 'should be able to set freeze pane');
|
||||
self::assertSame($topLeftCell, $actualTopLeftCell, 'should be able to set the top left cell');
|
||||
self::assertSame('A24', $reloadedActive->getSelectedCells(), 'selected cell should default to be first cell after the freeze pane');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue