1441 |
ariadna |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace PhpOffice\PhpSpreadsheet\Reader\Xml\Style;
|
|
|
4 |
|
|
|
5 |
use PhpOffice\PhpSpreadsheet\Style\Alignment as AlignmentStyles;
|
|
|
6 |
use SimpleXMLElement;
|
|
|
7 |
|
|
|
8 |
class Alignment extends StyleBase
|
|
|
9 |
{
|
|
|
10 |
protected const VERTICAL_ALIGNMENT_STYLES = [
|
|
|
11 |
AlignmentStyles::VERTICAL_BOTTOM,
|
|
|
12 |
AlignmentStyles::VERTICAL_TOP,
|
|
|
13 |
AlignmentStyles::VERTICAL_CENTER,
|
|
|
14 |
AlignmentStyles::VERTICAL_JUSTIFY,
|
|
|
15 |
];
|
|
|
16 |
|
|
|
17 |
protected const HORIZONTAL_ALIGNMENT_STYLES = [
|
|
|
18 |
AlignmentStyles::HORIZONTAL_GENERAL,
|
|
|
19 |
AlignmentStyles::HORIZONTAL_LEFT,
|
|
|
20 |
AlignmentStyles::HORIZONTAL_RIGHT,
|
|
|
21 |
AlignmentStyles::HORIZONTAL_CENTER,
|
|
|
22 |
AlignmentStyles::HORIZONTAL_CENTER_CONTINUOUS,
|
|
|
23 |
AlignmentStyles::HORIZONTAL_JUSTIFY,
|
|
|
24 |
];
|
|
|
25 |
|
|
|
26 |
public function parseStyle(SimpleXMLElement $styleAttributes): array
|
|
|
27 |
{
|
|
|
28 |
$style = [];
|
|
|
29 |
|
|
|
30 |
foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
|
|
|
31 |
$styleAttributeValue = (string) $styleAttributeValue;
|
|
|
32 |
switch ($styleAttributeKey) {
|
|
|
33 |
case 'Vertical':
|
|
|
34 |
if (self::identifyFixedStyleValue(self::VERTICAL_ALIGNMENT_STYLES, $styleAttributeValue)) {
|
|
|
35 |
$style['alignment']['vertical'] = $styleAttributeValue;
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
break;
|
|
|
39 |
case 'Horizontal':
|
|
|
40 |
if (self::identifyFixedStyleValue(self::HORIZONTAL_ALIGNMENT_STYLES, $styleAttributeValue)) {
|
|
|
41 |
$style['alignment']['horizontal'] = $styleAttributeValue;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
break;
|
|
|
45 |
case 'WrapText':
|
|
|
46 |
$style['alignment']['wrapText'] = true;
|
|
|
47 |
|
|
|
48 |
break;
|
|
|
49 |
case 'Rotate':
|
|
|
50 |
$style['alignment']['textRotation'] = $styleAttributeValue;
|
|
|
51 |
|
|
|
52 |
break;
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
return $style;
|
|
|
57 |
}
|
|
|
58 |
}
|