isCli()) { $helper->log('This example should only be run from a Web Browser' . PHP_EOL); return; } $negatives = [ CurrencyNegative::minus, CurrencyNegative::redMinus, CurrencyNegative::parentheses, CurrencyNegative::redParentheses, ]; $negativesString = [ 'CurrencyNegative::minus', 'CurrencyNegative::redMinus', 'CurrencyNegative::parentheses', 'CurrencyNegative::redParentheses', ]; $currencies = [ '$' => 'US Dollars ($)', '€' => 'Euro (€)', '¥' => 'Japanese Yen (¥)', '£' => 'Pound Sterling (£)', '₹' => 'Rupee (₹)', '₽' => 'Rouble (₽)', ]; $postNegative = StringHelper::convertPostToString('negative'); if (!in_array($postNegative, ['0', '1', '2', '3'], true)) { $postNegative = '0'; } $postNegative = (int) $postNegative; ?>

>
>Leading >Trailing
>Minus Sign >Red Minus Sign >Parentheses >Red Parentheses

log('The Sample Number Value must be numeric'); } elseif (!is_numeric($_POST['decimals']) || str_contains((string) $_POST['decimals'], '.') || (int) $_POST['decimals'] < 0) { $helper->log('The Decimal Places value must be positive integer'); } elseif (!in_array($_POST['currency'], array_keys($currencies), true)) { $helper->log('Unrecognized currency symbol'); } else { try { $negative = $negatives[$postNegative]; $wizard = new Wizard\Currency($_POST['currency'], (int) $_POST['decimals'], isset($_POST['thousands']), (bool) $_POST['position']); $wizard->setNegative($negative); $mask = $wizard->format(); $postNumber = StringHelper::convertPostToString('number'); $postCurrency = StringHelper::convertPostToString('currency'); $postDecimals = StringHelper::convertPostToString('decimals'); $example = (string) NumberFormat::toFormattedString((float) $postNumber, $mask, [HtmlWriter::class, 'formatColorStatic']); $helper->log('
Code:
'); $helper->log('use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;'); $helper->log('use PhpOffice\PhpSpreadsheet\Style\NumberFormat\CurrencyNegative;'); $helper->log( "\$wizard = new Wizard\\Currency('{$postCurrency}', {$postDecimals}, Wizard\\Number::" . (isset($_POST['thousands']) ? 'WITH_THOUSANDS_SEPARATOR' : 'WITHOUT_THOUSANDS_SEPARATOR') . ', Wizard\Currency::' . (((bool) $_POST['position']) ? 'LEADING_SYMBOL' : 'TRAILING_SYMBOL') . ');' ); $helper->log('$wizard->setNegative(' . $negativesString[$postNegative] . ');'); $helper->log('$mask = $wizard->format();'); $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()}"); } } }