forked from PHPOffice/PhpSpreadsheet
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Data Validations in More Versions of Excel
Attempt to deal with PHPOffice#2368, this time for good. Some deleted code was accidentally restored just before release 19, causing errors in spreadsheets with Data Validations. PR PHPOffice#2369 removed the duplicated code, and the fix was confirmed in current versions of Excel for Windows, Google sheets, and other versions of Excel. However, there were problems reported in earlier version of Excel for Windows, and some, versions of Excel for Mac, not all but including a recent one. This change, which is simpler than the original (no need for extLst) fix for DataValidations, is tested with Excel 2007 and Excel 2003 as well as more recent versions. I do not have a Mac on which to test.
- Loading branch information
Showing
2 changed files
with
59 additions
and
46 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,37 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx; | ||
|
||
use PhpOffice\PhpSpreadsheet\Cell\DataValidation; | ||
use PhpOffice\PhpSpreadsheet\Shared\File; | ||
use PhpOffice\PhpSpreadsheet\Spreadsheet; | ||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as Writer; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class Issue2368Test extends TestCase | ||
{ | ||
public function testBoolWrite(): void | ||
{ | ||
// DataValidations were incorrectly written twice. | ||
$spreadsheet = new Spreadsheet(); | ||
$sheet = $spreadsheet->getActiveSheet(); | ||
$validation = $sheet->getDataValidation('A1:A10'); | ||
$validation->setType(DataValidation::TYPE_LIST); | ||
$validation->setShowDropDown(true); | ||
$validation->setFormula1('"Option 1, Option 2"'); | ||
|
||
$outputFilename = File::temporaryFilename(); | ||
$writer = new Writer($spreadsheet); | ||
$writer->save($outputFilename); | ||
$zipfile = "zip://$outputFilename#xl/worksheets/sheet1.xml"; | ||
$contents = file_get_contents($zipfile); | ||
unlink($outputFilename); | ||
$spreadsheet->disconnectWorksheets(); | ||
if ($contents === false) { | ||
self::fail('Unable to open file'); | ||
} else { | ||
self::assertSame(0, substr_count($contents, '<extLst>')); | ||
self::assertSame(2, substr_count($contents, 'dataValidations')); // start and end tags | ||
} | ||
} | ||
} |