Make DefinedNames Samples Consistent With Other Samples (#1707)

All other Samples write to temporary directory. DefinedNames samples
write to main directory, which (a) means they aren't stored with others,
and (b) they aren't ignored by git so look like changed files.
The tests are also simplified by requiring Header rather than Bootstrap,
making use of Helper.
This commit is contained in:
oleibman 2020-11-11 02:02:04 -08:00 committed by GitHub
parent 0bf3986efa
commit 6fe653179f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 39 additions and 129 deletions

View File

@ -1,16 +1,9 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); require __DIR__ . '/../Header.php';
set_time_limit(0);
date_default_timezone_set('UTC');
// Adjust the path as required to reference the PHPSpreadsheet Bootstrap file
require_once __DIR__ . '/../Bootstrap.php';
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->setActiveSheetIndex(0); $worksheet = $spreadsheet->setActiveSheetIndex(0);
@ -51,13 +44,11 @@ $worksheet
->setCellValue("B{$row}", "=SUM(B{$startRow}:B{$endRow})") ->setCellValue("B{$row}", "=SUM(B{$startRow}:B{$endRow})")
->setCellValue("C{$row}", "=SUM(C{$startRow}:C{$endRow})"); ->setCellValue("C{$row}", "=SUM(C{$startRow}:C{$endRow})");
echo sprintf( $helper->log(sprintf(
'Worked %.2f hours at a rate of %.2f - Charge to the client is %.2f', 'Worked %.2f hours at a rate of %.2f - Charge to the client is %.2f',
$worksheet->getCell("B{$row}")->getCalculatedValue(), $worksheet->getCell("B{$row}")->getCalculatedValue(),
$worksheet->getCell('B1')->getValue(), $worksheet->getCell('B1')->getValue(),
$worksheet->getCell("C{$row}")->getCalculatedValue() $worksheet->getCell("C{$row}")->getCalculatedValue()
), PHP_EOL; ));
$outputFileName = 'AbsoluteNamedRange.xlsx'; $helper->write($spreadsheet, __FILE__, ['Xlsx']);
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save($outputFileName);

View File

@ -1,18 +1,11 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\NamedFormula; use PhpOffice\PhpSpreadsheet\NamedFormula;
use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
error_reporting(E_ALL); require_once __DIR__ . '/../Header.php';
set_time_limit(0);
date_default_timezone_set('UTC');
// Adjust the path as required to reference the PHPSpreadsheet Bootstrap file
require_once __DIR__ . '/../Bootstrap.php';
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
@ -91,9 +84,7 @@ for ($row = 2; $row <= 7; ++$row) {
$growth = $worksheet->getCell("B{$row}")->getFormattedValue(); $growth = $worksheet->getCell("B{$row}")->getFormattedValue();
$profitGrowth = $worksheet->getCell("C{$row}")->getFormattedValue(); $profitGrowth = $worksheet->getCell("C{$row}")->getFormattedValue();
echo "Growth for {$month} is {$growth}, with a Profit Growth of {$profitGrowth}", PHP_EOL; $helper->log("Growth for {$month} is {$growth}, with a Profit Growth of {$profitGrowth}");
} }
$outputFileName = 'CrossWorksheetNamedFormula.xlsx'; $helper->write($spreadsheet, __FILE__, ['Xlsx']);
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save($outputFileName);

View File

@ -1,17 +1,10 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\NamedFormula; use PhpOffice\PhpSpreadsheet\NamedFormula;
use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); require_once __DIR__ . '/../Header.php';
set_time_limit(0);
date_default_timezone_set('UTC');
// Adjust the path as required to reference the PHPSpreadsheet Bootstrap file
require_once __DIR__ . '/../Bootstrap.php';
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->setActiveSheetIndex(0); $worksheet = $spreadsheet->setActiveSheetIndex(0);
@ -62,13 +55,11 @@ $worksheet
->setCellValue("B{$row}", '=COLUMN_TOTALS') ->setCellValue("B{$row}", '=COLUMN_TOTALS')
->setCellValue("C{$row}", '=COLUMN_TOTALS'); ->setCellValue("C{$row}", '=COLUMN_TOTALS');
echo sprintf( $helper->log(sprintf(
'Worked %.2f hours at a rate of %.2f - Charge to the client is %.2f', 'Worked %.2f hours at a rate of %.2f - Charge to the client is %.2f',
$worksheet->getCell("B{$row}")->getCalculatedValue(), $worksheet->getCell("B{$row}")->getCalculatedValue(),
$worksheet->getCell('B1')->getValue(), $worksheet->getCell('B1')->getValue(),
$worksheet->getCell("C{$row}")->getCalculatedValue() $worksheet->getCell("C{$row}")->getCalculatedValue()
), PHP_EOL; ));
$outputFileName = 'NamedFormulaeAndRanges.xlsx'; $helper->write($spreadsheet, __FILE__, ['Xlsx']);
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save($outputFileName);

View File

@ -1,16 +1,9 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); require_once __DIR__ . '/../Header.php';
set_time_limit(0);
date_default_timezone_set('UTC');
// Adjust the path as required to reference the PHPSpreadsheet Bootstrap file
require_once __DIR__ . '/../Bootstrap.php';
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->setActiveSheetIndex(0); $worksheet = $spreadsheet->setActiveSheetIndex(0);
@ -54,13 +47,11 @@ $worksheet
->setCellValue("B{$row}", "=SUM(B{$startRow}:B{$endRow})") ->setCellValue("B{$row}", "=SUM(B{$startRow}:B{$endRow})")
->setCellValue("C{$row}", "=SUM(C{$startRow}:C{$endRow})"); ->setCellValue("C{$row}", "=SUM(C{$startRow}:C{$endRow})");
echo sprintf( $helper->log(sprintf(
'Worked %.2f hours at a rate of %.2f - Charge to the client is %.2f', 'Worked %.2f hours at a rate of %.2f - Charge to the client is %.2f',
$worksheet->getCell("B{$row}")->getCalculatedValue(), $worksheet->getCell("B{$row}")->getCalculatedValue(),
$worksheet->getCell('B1')->getValue(), $worksheet->getCell('B1')->getValue(),
$worksheet->getCell("C{$row}")->getCalculatedValue() $worksheet->getCell("C{$row}")->getCalculatedValue()
), PHP_EOL; ));
$outputFileName = 'RelativeNamedRange.xlsx'; $helper->write($spreadsheet, __FILE__, ['Xlsx']);
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save($outputFileName);

View File

@ -1,16 +1,9 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); require_once __DIR__ . '/../Header.php';
set_time_limit(0);
date_default_timezone_set('UTC');
// Adjust the path as required to reference the PHPSpreadsheet Bootstrap file
require_once __DIR__ . '/../Bootstrap.php';
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->setActiveSheetIndex(0); $worksheet = $spreadsheet->setActiveSheetIndex(0);
@ -57,13 +50,11 @@ $worksheet
->setCellValue("B{$row}", '=SUM(COLUMN_DATA_VALUES)') ->setCellValue("B{$row}", '=SUM(COLUMN_DATA_VALUES)')
->setCellValue("C{$row}", '=SUM(COLUMN_DATA_VALUES)'); ->setCellValue("C{$row}", '=SUM(COLUMN_DATA_VALUES)');
echo sprintf( $helper->log(sprintf(
'Worked %.2f hours at a rate of %.2f - Charge to the client is %.2f', 'Worked %.2f hours at a rate of %.2f - Charge to the client is %.2f',
$worksheet->getCell("B{$row}")->getCalculatedValue(), $worksheet->getCell("B{$row}")->getCalculatedValue(),
$worksheet->getCell('B1')->getValue(), $worksheet->getCell('B1')->getValue(),
$worksheet->getCell("C{$row}")->getCalculatedValue() $worksheet->getCell("C{$row}")->getCalculatedValue()
), PHP_EOL; ));
$outputFileName = 'RelativeNamedRange2.xlsx'; $helper->write($spreadsheet, __FILE__, ['Xlsx']);
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save($outputFileName);

View File

@ -1,17 +1,10 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\NamedFormula; use PhpOffice\PhpSpreadsheet\NamedFormula;
use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); require_once __DIR__ . '/../Header.php';
set_time_limit(0);
date_default_timezone_set('UTC');
// Adjust the path as required to reference the PHPSpreadsheet Bootstrap file
require_once __DIR__ . '/../Bootstrap.php';
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->setActiveSheetIndex(0); $worksheet = $spreadsheet->setActiveSheetIndex(0);
@ -60,13 +53,11 @@ $worksheet
->setCellValue("B{$row}", '=SUM(COLUMN_DATA_VALUES)') ->setCellValue("B{$row}", '=SUM(COLUMN_DATA_VALUES)')
->setCellValue("C{$row}", '=SUM(COLUMN_DATA_VALUES)'); ->setCellValue("C{$row}", '=SUM(COLUMN_DATA_VALUES)');
echo sprintf( $helper->log(sprintf(
'Worked %.2f hours at a rate of %.2f - Charge to the client is %.2f', 'Worked %.2f hours at a rate of %.2f - Charge to the client is %.2f',
$worksheet->getCell("B{$row}")->getCalculatedValue(), $worksheet->getCell("B{$row}")->getCalculatedValue(),
$worksheet->getCell('B1')->getValue(), $worksheet->getCell('B1')->getValue(),
$worksheet->getCell("C{$row}")->getCalculatedValue() $worksheet->getCell("C{$row}")->getCalculatedValue()
), PHP_EOL; ));
$outputFileName = 'RelativeNamedRangeAsFunction.xlsx'; $helper->write($spreadsheet, __FILE__, ['Xlsx']);
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save($outputFileName);

View File

@ -1,16 +1,9 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); require_once __DIR__ . '/../Header.php';
set_time_limit(0);
date_default_timezone_set('UTC');
// Adjust the path as required to reference the PHPSpreadsheet Bootstrap file
require_once __DIR__ . '/../Bootstrap.php';
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->setActiveSheetIndex(0); $worksheet = $spreadsheet->setActiveSheetIndex(0);
@ -67,15 +60,13 @@ $worksheet
->setCellValue("B{$row}", '=SUM(COLUMN_DATA_VALUES)') ->setCellValue("B{$row}", '=SUM(COLUMN_DATA_VALUES)')
->setCellValue("C{$row}", '=SUM(COLUMN_DATA_VALUES)'); ->setCellValue("C{$row}", '=SUM(COLUMN_DATA_VALUES)');
echo sprintf( $helper->log(sprintf(
'Worked %.2f hours at a rate of %s - Charge to the client is %.2f', 'Worked %.2f hours at a rate of %s - Charge to the client is %.2f',
$worksheet->getCell("B{$row}")->getCalculatedValue(), $worksheet->getCell("B{$row}")->getCalculatedValue(),
$chargeRateCellValue = $spreadsheet $chargeRateCellValue = $spreadsheet
->getSheetByName($spreadsheet->getNamedRange('CHARGE_RATE')->getWorksheet()->getTitle()) ->getSheetByName($spreadsheet->getNamedRange('CHARGE_RATE')->getWorksheet()->getTitle())
->getCell($spreadsheet->getNamedRange('CHARGE_RATE')->getCellsInRange()[0])->getValue(), ->getCell($spreadsheet->getNamedRange('CHARGE_RATE')->getCellsInRange()[0])->getValue(),
$worksheet->getCell("C{$row}")->getCalculatedValue() $worksheet->getCell("C{$row}")->getCalculatedValue()
), PHP_EOL; ));
$outputFileName = 'ScopedNamedRange.xlsx'; $helper->write($spreadsheet, __FILE__, ['Xlsx']);
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save($outputFileName);

View File

@ -1,16 +1,9 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); require_once __DIR__ . '/../Header.php';
set_time_limit(0);
date_default_timezone_set('UTC');
// Adjust the path as required to reference the PHPSpreadsheet Bootstrap file
require_once __DIR__ . '/../Bootstrap.php';
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->setActiveSheetIndex(0); $worksheet = $spreadsheet->setActiveSheetIndex(0);
@ -83,16 +76,14 @@ $worksheet
->setCellValue('B1', 4.5); ->setCellValue('B1', 4.5);
foreach ($spreadsheet->getAllSheets() as $worksheet) { foreach ($spreadsheet->getAllSheets() as $worksheet) {
echo sprintf( $helper->log(sprintf(
'Worked %.2f hours for "%s" at a rate of %.2f - Charge to the client is %.2f', 'Worked %.2f hours for "%s" at a rate of %.2f - Charge to the client is %.2f',
$worksheet->getCell("B{$row}")->getCalculatedValue(), $worksheet->getCell("B{$row}")->getCalculatedValue(),
$worksheet->getTitle(), $worksheet->getTitle(),
$worksheet->getCell('B1')->getValue(), $worksheet->getCell('B1')->getValue(),
$worksheet->getCell("C{$row}")->getCalculatedValue() $worksheet->getCell("C{$row}")->getCalculatedValue()
), PHP_EOL; ));
} }
$worksheet = $spreadsheet->setActiveSheetIndex(0); $worksheet = $spreadsheet->setActiveSheetIndex(0);
$outputFileName = 'ScopedNamedRange2.xlsx'; $helper->write($spreadsheet, __FILE__, ['Xlsx']);
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save($outputFileName);

View File

@ -1,17 +1,10 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\NamedFormula; use PhpOffice\PhpSpreadsheet\NamedFormula;
use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); require_once __DIR__ . '/../Header.php';
set_time_limit(0);
date_default_timezone_set('UTC');
// Adjust the path as required to reference the PHPSpreadsheet Bootstrap file
require_once __DIR__ . '/../Bootstrap.php';
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->setActiveSheetIndex(0); $worksheet = $spreadsheet->setActiveSheetIndex(0);
@ -39,14 +32,12 @@ $worksheet
->setCellValue('B4', '=TAX') ->setCellValue('B4', '=TAX')
->setCellValue('B5', '=PRICE+TAX'); ->setCellValue('B5', '=PRICE+TAX');
echo sprintf( $helper->log(sprintf(
'With a Tax Rate of %.2f and a net price of %.2f, Tax is %.2f and the gross price is %.2f', 'With a Tax Rate of %.2f and a net price of %.2f, Tax is %.2f and the gross price is %.2f',
$worksheet->getCell('B1')->getCalculatedValue(), $worksheet->getCell('B1')->getCalculatedValue(),
$worksheet->getCell('B3')->getValue(), $worksheet->getCell('B3')->getValue(),
$worksheet->getCell('B4')->getCalculatedValue(), $worksheet->getCell('B4')->getCalculatedValue(),
$worksheet->getCell('B5')->getCalculatedValue() $worksheet->getCell('B5')->getCalculatedValue()
), PHP_EOL; ));
$outputFileName = 'SimpleNamedFormula.xlsx'; $helper->write($spreadsheet, __FILE__, ['Xlsx']);
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save($outputFileName);

View File

@ -1,16 +1,9 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); require_once __DIR__ . '/../Header.php';
set_time_limit(0);
date_default_timezone_set('UTC');
// Adjust the path as required to reference the PHPSpreadsheet Bootstrap file
require_once __DIR__ . '/../Bootstrap.php';
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->setActiveSheetIndex(0); $worksheet = $spreadsheet->setActiveSheetIndex(0);
@ -33,14 +26,12 @@ $worksheet
->setCellValue('B4', '=PRICE*TAX_RATE') ->setCellValue('B4', '=PRICE*TAX_RATE')
->setCellValue('B5', '=PRICE*(1+TAX_RATE)'); ->setCellValue('B5', '=PRICE*(1+TAX_RATE)');
echo sprintf( $helper->log(sprintf(
'With a Tax Rate of %.2f and a net price of %.2f, Tax is %.2f and the gross price is %.2f', 'With a Tax Rate of %.2f and a net price of %.2f, Tax is %.2f and the gross price is %.2f',
$worksheet->getCell('B1')->getCalculatedValue(), $worksheet->getCell('B1')->getCalculatedValue(),
$worksheet->getCell('B3')->getValue(), $worksheet->getCell('B3')->getValue(),
$worksheet->getCell('B4')->getCalculatedValue(), $worksheet->getCell('B4')->getCalculatedValue(),
$worksheet->getCell('B5')->getCalculatedValue() $worksheet->getCell('B5')->getCalculatedValue()
), PHP_EOL; ));
$outputFileName = 'SimpleNamedRange.xlsx'; $helper->write($spreadsheet, __FILE__, ['Xlsx']);
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save($outputFileName);