diff --git a/samples/Basic/45_Quadratic_equation_solver.php b/samples/Basic/45_Quadratic_equation_solver.php
index 83a2000ff4..8e798da2f3 100644
--- a/samples/Basic/45_Quadratic_equation_solver.php
+++ b/samples/Basic/45_Quadratic_equation_solver.php
@@ -1,9 +1,17 @@
isCli()) {
+ $helper->log('This example should only be run from a Web Browser' . PHP_EOL);
+
+ return;
+}
?>
+
+log('The Sample Number Value must be numeric');
+ } elseif (!is_numeric($_POST['decimals']) || strpos($_POST['decimals'], '.') !== false || (int) $_POST['decimals'] < 0) {
+ $helper->log('The Decimal Places value must be positive integer');
+ } else {
+ try {
+ $wizard = new Wizard\Accounting($_POST['currency'], $_POST['decimals'], isset($_POST['thousands']), (bool) $_POST['position'], (bool) $_POST['spacing']);
+ $mask = $wizard->format();
+ $example = (string) NumberFormat::toFormattedString((float) $_POST['number'], $mask);
+ $helper->log('
Code:
');
+ $helper->log('use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;');
+ $helper->log(
+ "\$mask = Wizard\\Accounting('{$_POST['currency']}', {$_POST['decimals']}, Wizard\\Number::" .
+ (isset($_POST['thousands']) ? 'WITH_THOUSANDS_SEPARATOR' : 'WITHOUT_THOUSANDS_SEPARATOR') .
+ ', Wizard\Currency::' . (((bool) $_POST['position']) ? 'LEADING_SYMBOL' : 'TRAILING_SYMBOL') .
+ ', Wizard\Currency::' . (((bool) $_POST['spacing']) ? 'SYMBOL_WITH_SPACING' : 'SYMBOL_WITHOUT_SPACING') .
+ ');
'
+ );
+ $helper->log('echo (string) $mask;');
+ $helper->log('
Mask:
');
+ $helper->log($mask . '
');
+ $helper->log('
Example:
');
+ $helper->log($example);
+ } catch (SpreadsheetException $e) {
+ $helper->log("Exception: {$e->getMessage()}");
+ }
+ }
+}
diff --git a/samples/Wizards/NumberFormat/Currency.php b/samples/Wizards/NumberFormat/Currency.php
new file mode 100644
index 0000000000..b4373d5415
--- /dev/null
+++ b/samples/Wizards/NumberFormat/Currency.php
@@ -0,0 +1,111 @@
+isCli()) {
+ $helper->log('This example should only be run from a Web Browser' . PHP_EOL);
+
+ return;
+}
+
+$currencies = [
+ '$' => 'US Dollars ($)',
+ '€' => 'Euro (€)',
+ '¥' => 'Japanese Yen (¥)',
+ '£' => 'Pound Sterling (£)',
+ '₹' => 'Rupee (₹)',
+ '₽' => 'Rouble (₽)',
+];
+
+?>
+
+
+log('The Sample Number Value must be numeric');
+ } elseif (!is_numeric($_POST['decimals']) || strpos($_POST['decimals'], '.') !== false || (int) $_POST['decimals'] < 0) {
+ $helper->log('The Decimal Places value must be positive integer');
+ } else {
+ try {
+ $wizard = new Wizard\Currency($_POST['currency'], $_POST['decimals'], isset($_POST['thousands']), (bool) $_POST['position'], (bool) $_POST['spacing']);
+ $mask = $wizard->format();
+ $example = (string) NumberFormat::toFormattedString((float) $_POST['number'], $mask);
+ $helper->log('
Code:
');
+ $helper->log('use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;');
+ $helper->log(
+ "\$mask = Wizard\\Currency('{$_POST['currency']}', {$_POST['decimals']}, Wizard\\Number::" .
+ (isset($_POST['thousands']) ? 'WITH_THOUSANDS_SEPARATOR' : 'WITHOUT_THOUSANDS_SEPARATOR') .
+ ', Wizard\Currency::' . (((bool) $_POST['position']) ? 'LEADING_SYMBOL' : 'TRAILING_SYMBOL') .
+ ', Wizard\Currency::' . (((bool) $_POST['spacing']) ? 'SYMBOL_WITH_SPACING' : 'SYMBOL_WITHOUT_SPACING') .
+ ');
'
+ );
+ $helper->log('echo (string) $mask;');
+ $helper->log('
Mask:
');
+ $helper->log($mask . '
');
+ $helper->log('
Example:
');
+ $helper->log($example);
+ } catch (SpreadsheetException $e) {
+ $helper->log("Exception: {$e->getMessage()}");
+ }
+ }
+}
diff --git a/samples/Wizards/NumberFormat/Number.php b/samples/Wizards/NumberFormat/Number.php
new file mode 100644
index 0000000000..7869838abc
--- /dev/null
+++ b/samples/Wizards/NumberFormat/Number.php
@@ -0,0 +1,75 @@
+isCli()) {
+ $helper->log('This example should only be run from a Web Browser' . PHP_EOL);
+
+ return;
+}
+?>
+
+
+log('The Sample Number Value must be numeric');
+ } elseif (!is_numeric($_POST['decimals']) || strpos($_POST['decimals'], '.') !== false || (int) $_POST['decimals'] < 0) {
+ $helper->log('The Decimal Places value must be positive integer');
+ } else {
+ try {
+ $wizard = new Wizard\Number($_POST['decimals'], isset($_POST['thousands']));
+ $mask = $wizard->format();
+ $example = NumberFormat::toFormattedString((float) $_POST['number'], $mask);
+ $helper->log('
Code:
');
+ $helper->log('use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;');
+ $helper->log(
+ "\$mask = Wizard\\Number({$_POST['decimals']}, Wizard\\Number::" .
+ (isset($_POST['thousands']) ? 'WITH_THOUSANDS_SEPARATOR' : 'WITHOUT_THOUSANDS_SEPARATOR') .
+ ');
'
+ );
+ $helper->log('echo (string) $mask;');
+ $helper->log('
Mask:');
+ $helper->log($mask);
+ $helper->log('Example:');
+ $helper->log($example);
+ } catch (SpreadsheetException $e) {
+ $helper->log("Exception: {$e->getMessage()}");
+ }
+ }
+}
diff --git a/samples/Wizards/NumberFormat/Percentage.php b/samples/Wizards/NumberFormat/Percentage.php
new file mode 100644
index 0000000000..a1bde45c9b
--- /dev/null
+++ b/samples/Wizards/NumberFormat/Percentage.php
@@ -0,0 +1,65 @@
+isCli()) {
+ $helper->log('This example should only be run from a Web Browser' . PHP_EOL);
+
+ return;
+}
+?>
+
+
+log('The Sample Number Value must be numeric');
+ } elseif (!is_numeric($_POST['decimals']) || strpos($_POST['decimals'], '.') !== false || (int) $_POST['decimals'] < 0) {
+ $helper->log('The Decimal Places value must be positive integer');
+ } else {
+ try {
+ $wizard = new Wizard\Percentage($_POST['decimals']);
+ $mask = $wizard->format();
+ $example = (string) NumberFormat::toFormattedString((float) $_POST['number'], $mask);
+ $helper->log('
Code:
');
+ $helper->log('use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;');
+ $helper->log("\$mask = Wizard\\Percentage({$_POST['decimals']});
");
+ $helper->log('echo (string) $mask;');
+ $helper->log('
Mask:
');
+ $helper->log($mask . '
');
+ $helper->log('
Example:
');
+ $helper->log($example);
+ } catch (SpreadsheetException $e) {
+ $helper->log("Exception: {$e->getMessage()}");
+ }
+ }
+}
diff --git a/samples/Wizards/NumberFormat/Scientific.php b/samples/Wizards/NumberFormat/Scientific.php
new file mode 100644
index 0000000000..d35f43903a
--- /dev/null
+++ b/samples/Wizards/NumberFormat/Scientific.php
@@ -0,0 +1,65 @@
+isCli()) {
+ $helper->log('This example should only be run from a Web Browser' . PHP_EOL);
+
+ return;
+}
+?>
+
+
+log('The Sample Number Value must be numeric');
+ } elseif (!is_numeric($_POST['decimals']) || strpos($_POST['decimals'], '.') !== false || (int) $_POST['decimals'] < 0) {
+ $helper->log('The Decimal Places value must be positive integer');
+ } else {
+ try {
+ $wizard = new Wizard\Scientific($_POST['decimals']);
+ $mask = $wizard->format();
+ $example = (string) NumberFormat::toFormattedString((float) $_POST['number'], $mask);
+ $helper->log('
Code:
');
+ $helper->log('use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;');
+ $helper->log("\$mask = Wizard\\Scientific({$_POST['decimals']});
");
+ $helper->log('echo (string) $mask;');
+ $helper->log('
Mask:
');
+ $helper->log($mask . '
');
+ $helper->log('
Example:
');
+ $helper->log($example);
+ } catch (SpreadsheetException $e) {
+ $helper->log("Exception: {$e->getMessage()}");
+ }
+ }
+}
diff --git a/src/PhpSpreadsheet/Helper/Sample.php b/src/PhpSpreadsheet/Helper/Sample.php
index 5ca546e077..4ed0be400b 100644
--- a/src/PhpSpreadsheet/Helper/Sample.php
+++ b/src/PhpSpreadsheet/Helper/Sample.php
@@ -195,7 +195,7 @@ public function getTemporaryFilename($extension = 'xlsx')
public function log(string $message): void
{
$eol = $this->isCli() ? PHP_EOL : '
';
- echo date('H:i:s ') . $message . $eol;
+ echo($this->isCli() ? date('H:i:s ') : '') . $message . $eol;
}
public function titles(string $category, string $functionName, ?string $description = null): void