1 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace PhpOffice\PhpSpreadsheet\Reader\Xml\Style;
|
|
|
4 |
|
|
|
5 |
use PhpOffice\PhpSpreadsheet\Style\Fill as FillStyles;
|
|
|
6 |
use SimpleXMLElement;
|
|
|
7 |
|
|
|
8 |
class Fill extends StyleBase
|
|
|
9 |
{
|
|
|
10 |
/**
|
|
|
11 |
* @var array
|
|
|
12 |
*/
|
|
|
13 |
public const FILL_MAPPINGS = [
|
|
|
14 |
'fillType' => [
|
|
|
15 |
'solid' => FillStyles::FILL_SOLID,
|
|
|
16 |
'gray75' => FillStyles::FILL_PATTERN_DARKGRAY,
|
|
|
17 |
'gray50' => FillStyles::FILL_PATTERN_MEDIUMGRAY,
|
|
|
18 |
'gray25' => FillStyles::FILL_PATTERN_LIGHTGRAY,
|
|
|
19 |
'gray125' => FillStyles::FILL_PATTERN_GRAY125,
|
|
|
20 |
'gray0625' => FillStyles::FILL_PATTERN_GRAY0625,
|
|
|
21 |
'horzstripe' => FillStyles::FILL_PATTERN_DARKHORIZONTAL, // horizontal stripe
|
|
|
22 |
'vertstripe' => FillStyles::FILL_PATTERN_DARKVERTICAL, // vertical stripe
|
|
|
23 |
'reversediagstripe' => FillStyles::FILL_PATTERN_DARKUP, // reverse diagonal stripe
|
|
|
24 |
'diagstripe' => FillStyles::FILL_PATTERN_DARKDOWN, // diagonal stripe
|
|
|
25 |
'diagcross' => FillStyles::FILL_PATTERN_DARKGRID, // diagoanl crosshatch
|
|
|
26 |
'thickdiagcross' => FillStyles::FILL_PATTERN_DARKTRELLIS, // thick diagonal crosshatch
|
|
|
27 |
'thinhorzstripe' => FillStyles::FILL_PATTERN_LIGHTHORIZONTAL,
|
|
|
28 |
'thinvertstripe' => FillStyles::FILL_PATTERN_LIGHTVERTICAL,
|
|
|
29 |
'thinreversediagstripe' => FillStyles::FILL_PATTERN_LIGHTUP,
|
|
|
30 |
'thindiagstripe' => FillStyles::FILL_PATTERN_LIGHTDOWN,
|
|
|
31 |
'thinhorzcross' => FillStyles::FILL_PATTERN_LIGHTGRID, // thin horizontal crosshatch
|
|
|
32 |
'thindiagcross' => FillStyles::FILL_PATTERN_LIGHTTRELLIS, // thin diagonal crosshatch
|
|
|
33 |
],
|
|
|
34 |
];
|
|
|
35 |
|
|
|
36 |
public function parseStyle(SimpleXMLElement $styleAttributes): array
|
|
|
37 |
{
|
|
|
38 |
$style = [];
|
|
|
39 |
|
|
|
40 |
foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValuex) {
|
|
|
41 |
$styleAttributeValue = (string) $styleAttributeValuex;
|
|
|
42 |
switch ($styleAttributeKey) {
|
|
|
43 |
case 'Color':
|
|
|
44 |
$style['fill']['endColor']['rgb'] = substr($styleAttributeValue, 1);
|
|
|
45 |
$style['fill']['startColor']['rgb'] = substr($styleAttributeValue, 1);
|
|
|
46 |
|
|
|
47 |
break;
|
|
|
48 |
case 'PatternColor':
|
|
|
49 |
$style['fill']['startColor']['rgb'] = substr($styleAttributeValue, 1);
|
|
|
50 |
|
|
|
51 |
break;
|
|
|
52 |
case 'Pattern':
|
|
|
53 |
$lcStyleAttributeValue = strtolower((string) $styleAttributeValue);
|
|
|
54 |
$style['fill']['fillType']
|
|
|
55 |
= self::FILL_MAPPINGS['fillType'][$lcStyleAttributeValue] ?? FillStyles::FILL_NONE;
|
|
|
56 |
|
|
|
57 |
break;
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
return $style;
|
|
|
62 |
}
|
|
|
63 |
}
|