-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for Xls BIFF Window2 record structure where selected and active s…
…heets are stored. Added some tests for active sheet and selected cells in Xls.
- Loading branch information
Showing
3 changed files
with
127 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Functional; | ||
|
||
use PhpOffice\PhpSpreadsheet\Spreadsheet; | ||
|
||
class ActiveSheetTest extends AbstractFunctional | ||
{ | ||
public function providerFormats() | ||
{ | ||
return [ | ||
['Xls'], | ||
]; | ||
} | ||
|
||
/** | ||
* Test load file with correct active sheet. | ||
* | ||
* @dataProvider providerFormats | ||
* | ||
* @param string $format | ||
*/ | ||
public function testActiveSheet($format) | ||
{ | ||
$spreadsheet = new Spreadsheet(); | ||
|
||
$spreadsheet->setActiveSheetIndex(0) | ||
->setTitle('Test1') | ||
->setCellValue('D1', 1) | ||
->setCellValue('D2', 2) | ||
->setCellValue('D3', 3) | ||
->setCellValue('D4', 4) | ||
->setCellValue('D5', '=SUM(D1:D4)') | ||
->setSelectedCell('B2'); | ||
|
||
$spreadsheet->createSheet(1); | ||
|
||
$spreadsheet->setActiveSheetIndex(1) | ||
->setTitle('Test2') | ||
->setCellValue('D1', 4) | ||
->setCellValue('E1', 3) | ||
->setCellValue('F1', 2) | ||
->setCellValue('G1', 1) | ||
->setCellValue('H1', '=SUM(D1:G4)') | ||
->setSelectedCells('A1:B2'); | ||
|
||
$spreadsheet->createSheet(2); | ||
|
||
$spreadsheet->setActiveSheetIndex(2) | ||
->setTitle('Test3') | ||
->setCellValue('A1', 4) | ||
->setCellValue('B1', 3) | ||
->setCellValue('C1', 2) | ||
->setCellValue('D1', 1) | ||
->setCellValue('E1', '=SUM(A1:D4)') | ||
->setSelectedCells('A1:D1'); | ||
|
||
$spreadsheet->setActiveSheetIndex(1); | ||
|
||
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format); | ||
|
||
// Original object. | ||
self::assertSame(1, $spreadsheet->getActiveSheetIndex()); | ||
|
||
// Saved and reloaded file. | ||
self::assertSame(1, $reloadedSpreadsheet->getActiveSheetIndex()); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
tests/PhpSpreadsheetTests/Functional/SelectedCellsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Functional; | ||
|
||
use PhpOffice\PhpSpreadsheet\Spreadsheet; | ||
|
||
class SelectedCellsTest extends AbstractFunctional | ||
{ | ||
public function providerFormats() | ||
{ | ||
return [ | ||
['Xls'], | ||
]; | ||
} | ||
|
||
/** | ||
* Test load file with correct selected cells. | ||
* | ||
* @dataProvider providerFormats | ||
* | ||
* @param string $format | ||
*/ | ||
public function testSelectedCells($format) | ||
{ | ||
$spreadsheet = new Spreadsheet(); | ||
|
||
$spreadsheet->setActiveSheetIndex(0) | ||
->setTitle('Test1') | ||
->setCellValue('D1', 1) | ||
->setCellValue('D2', 2) | ||
->setCellValue('D3', 3) | ||
->setCellValue('D4', 4) | ||
->setCellValue('D5', '=SUM(D1:D4)') | ||
->setSelectedCell('B2'); | ||
|
||
$spreadsheet->createSheet(1); | ||
|
||
$spreadsheet->setActiveSheetIndex(1) | ||
->setTitle('Test2') | ||
->setCellValue('D1', 4) | ||
->setCellValue('E1', 3) | ||
->setCellValue('F1', 2) | ||
->setCellValue('G1', 1) | ||
->setCellValue('H1', '=SUM(D1:G4)') | ||
->setSelectedCells('A1:B2'); | ||
|
||
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format); | ||
|
||
// Original object. | ||
self::assertSame('B2', $spreadsheet->setActiveSheetIndex(0)->getSelectedCells()); | ||
self::assertSame('A1:B2', $spreadsheet->setActiveSheetIndex(1)->getSelectedCells()); | ||
|
||
// Saved and reloaded file. | ||
self::assertSame('B2', $reloadedSpreadsheet->setActiveSheetIndex(0)->getSelectedCells()); | ||
self::assertSame('A1:B2', $reloadedSpreadsheet->setActiveSheetIndex(1)->getSelectedCells()); | ||
} | ||
} |