Skip to content

Commit

Permalink
Allow color palette index values in number format masks
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkBaker committed Apr 5, 2023
1 parent 5da2f6e commit 04afee1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/PhpSpreadsheet/Style/NumberFormat/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ private static function splitFormatForSectionSelection(array $sections, $value):
// 3 sections: [POSITIVE/TEXT] [NEGATIVE] [ZERO]
// 4 sections: [POSITIVE] [NEGATIVE] [ZERO] [TEXT]
$sectionCount = count($sections);
$color_regex = '/\\[(' . implode('|', Color::NAMED_COLORS) . ')\\]/mui';
// Colour could be a named colour, or a numeric entry in the colour-index palette
$color_regex = '/\\[(' . implode('|', Color::NAMED_COLORS) . '|color \\d+)\\]/mui';
$cond_regex = '/\\[(>|>=|<|<=|=|<>)([+-]?\\d+([.]\\d+)?)\\]/';
$colors = ['', '', '', '', ''];
$conditionOperations = ['', '', '', '', ''];
Expand Down
11 changes: 11 additions & 0 deletions tests/data/Style/NumberFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,17 @@
-2,
'[Green]"Positive";[Red]"Negative";[Blue]"Zero"',
],
// Colour palette index
[
'+710',
710,
'[color 10]+#,##0;[color 12]-#,##0',
],
[
'-710',
-710,
'[color 10]+#,##0;[color 12]-#,##0',
],
// Value break points
[
'<=3500 red',
Expand Down

0 comments on commit 04afee1

Please sign in to comment.