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:
Bill Blume 2018-06-05 19:36:32 -07:00 committed by Adrien Crivelli
parent e3fb160f5f
commit 4c09d4f668
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
3 changed files with 39 additions and 1 deletions

View File

@ -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) - 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) - `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) - 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 ## [1.2.1] - 2018-04-10

View File

@ -246,6 +246,7 @@ class Worksheet extends WriterPart
} }
$activeCell = $pSheet->getActiveCell(); $activeCell = $pSheet->getActiveCell();
$sqref = $pSheet->getSelectedCells();
// Pane // Pane
$pane = ''; $pane = '';
@ -257,6 +258,7 @@ class Worksheet extends WriterPart
$topLeftCell = $pSheet->getTopLeftCell(); $topLeftCell = $pSheet->getTopLeftCell();
$activeCell = $topLeftCell; $activeCell = $topLeftCell;
$sqref = $topLeftCell;
// pane // pane
$pane = 'topRight'; $pane = 'topRight';
@ -292,7 +294,7 @@ class Worksheet extends WriterPart
$objWriter->writeAttribute('pane', $pane); $objWriter->writeAttribute('pane', $pane);
} }
$objWriter->writeAttribute('activeCell', $activeCell); $objWriter->writeAttribute('activeCell', $activeCell);
$objWriter->writeAttribute('sqref', $pSheet->getSelectedCells()); $objWriter->writeAttribute('sqref', $sqref);
$objWriter->endElement(); $objWriter->endElement();
$objWriter->endElement(); $objWriter->endElement();

View File

@ -37,4 +37,39 @@ class FreezePaneTest extends AbstractFunctional
self::assertSame($cellSplit, $actualCellSplit, 'should be able to set freeze pane'); 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($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');
}
} }