From ce5f91e6a1035cb66942c1f22d29dc37e7a6b75d Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Wed, 9 Mar 2022 18:55:31 -0800 Subject: [PATCH] Fix Sample39 (#2664) Sample39 was not adjusted when Defined Name support was changed to include both relative and absolute addresses. As a result, the Xlsx output is currently incorrect. The Xls output is in even worse shape, since PhpSpreadsheet 'Cannot yet write formulae with defined names to Xls' (see Writer/Xls/Parser.php). (Working around that restriction was the reason for my first contribution to this project.) The sample is changed to define its named ranges properly, and to produce only Xlsx output. --- samples/Basic/39_Dropdown.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/samples/Basic/39_Dropdown.php b/samples/Basic/39_Dropdown.php index e34d73e6..0e8ff52b 100644 --- a/samples/Basic/39_Dropdown.php +++ b/samples/Basic/39_Dropdown.php @@ -46,7 +46,7 @@ foreach ($continents as $key => $filename) { new NamedRange( $continent, $spreadsheet->getActiveSheet(), - $column . '1:' . $column . $countryCount + '$' . $column . '$1:$' . $column . '$' . $countryCount ) ); $spreadsheet->getActiveSheet() @@ -68,7 +68,7 @@ $spreadsheet->addNamedRange( new NamedRange( 'Continents', $spreadsheet->getActiveSheet(), - $continentColumn . '1:' . $continentColumn . count($continents) + '$' . $continentColumn . '$1:$' . $continentColumn . '$' . count($continents) ) ); @@ -126,4 +126,5 @@ $spreadsheet->getActiveSheet()->getColumnDimension('A')->setWidth(12); $spreadsheet->getActiveSheet()->getColumnDimension('B')->setWidth(30); // Save -$helper->write($spreadsheet, __FILE__); +$helper->log('Not writing to Xls - formulae with defined names not yet supported'); +$helper->write($spreadsheet, __FILE__, ['Xlsx']);