This commit is contained in:
steven 2025-08-11 22:23:30 +02:00
commit 72a26edcff
22092 changed files with 2101903 additions and 0 deletions

View file

@ -0,0 +1,58 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Reader\Xml\Style;
use PhpOffice\PhpSpreadsheet\Style\Alignment as AlignmentStyles;
use SimpleXMLElement;
class Alignment extends StyleBase
{
protected const VERTICAL_ALIGNMENT_STYLES = [
AlignmentStyles::VERTICAL_BOTTOM,
AlignmentStyles::VERTICAL_TOP,
AlignmentStyles::VERTICAL_CENTER,
AlignmentStyles::VERTICAL_JUSTIFY,
];
protected const HORIZONTAL_ALIGNMENT_STYLES = [
AlignmentStyles::HORIZONTAL_GENERAL,
AlignmentStyles::HORIZONTAL_LEFT,
AlignmentStyles::HORIZONTAL_RIGHT,
AlignmentStyles::HORIZONTAL_CENTER,
AlignmentStyles::HORIZONTAL_CENTER_CONTINUOUS,
AlignmentStyles::HORIZONTAL_JUSTIFY,
];
public function parseStyle(SimpleXMLElement $styleAttributes): array
{
$style = [];
foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
$styleAttributeValue = (string) $styleAttributeValue;
switch ($styleAttributeKey) {
case 'Vertical':
if (self::identifyFixedStyleValue(self::VERTICAL_ALIGNMENT_STYLES, $styleAttributeValue)) {
$style['alignment']['vertical'] = $styleAttributeValue;
}
break;
case 'Horizontal':
if (self::identifyFixedStyleValue(self::HORIZONTAL_ALIGNMENT_STYLES, $styleAttributeValue)) {
$style['alignment']['horizontal'] = $styleAttributeValue;
}
break;
case 'WrapText':
$style['alignment']['wrapText'] = true;
break;
case 'Rotate':
$style['alignment']['textRotation'] = $styleAttributeValue;
break;
}
}
return $style;
}
}

View file

@ -0,0 +1,98 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Reader\Xml\Style;
use PhpOffice\PhpSpreadsheet\Style\Border as BorderStyle;
use PhpOffice\PhpSpreadsheet\Style\Borders;
use SimpleXMLElement;
class Border extends StyleBase
{
protected const BORDER_POSITIONS = [
'top',
'left',
'bottom',
'right',
];
/**
* @var array
*/
public const BORDER_MAPPINGS = [
'borderStyle' => [
'1continuous' => BorderStyle::BORDER_THIN,
'1dash' => BorderStyle::BORDER_DASHED,
'1dashdot' => BorderStyle::BORDER_DASHDOT,
'1dashdotdot' => BorderStyle::BORDER_DASHDOTDOT,
'1dot' => BorderStyle::BORDER_DOTTED,
'1double' => BorderStyle::BORDER_DOUBLE,
'2continuous' => BorderStyle::BORDER_MEDIUM,
'2dash' => BorderStyle::BORDER_MEDIUMDASHED,
'2dashdot' => BorderStyle::BORDER_MEDIUMDASHDOT,
'2dashdotdot' => BorderStyle::BORDER_MEDIUMDASHDOTDOT,
'2dot' => BorderStyle::BORDER_DOTTED,
'2double' => BorderStyle::BORDER_DOUBLE,
'3continuous' => BorderStyle::BORDER_THICK,
'3dash' => BorderStyle::BORDER_MEDIUMDASHED,
'3dashdot' => BorderStyle::BORDER_MEDIUMDASHDOT,
'3dashdotdot' => BorderStyle::BORDER_MEDIUMDASHDOTDOT,
'3dot' => BorderStyle::BORDER_DOTTED,
'3double' => BorderStyle::BORDER_DOUBLE,
],
];
public function parseStyle(SimpleXMLElement $styleData, array $namespaces): array
{
$style = [];
$diagonalDirection = '';
$borderPosition = '';
foreach ($styleData->Border as $borderStyle) {
$borderAttributes = self::getAttributes($borderStyle, $namespaces['ss']);
$thisBorder = [];
$styleType = (string) $borderAttributes->Weight;
$styleType .= strtolower((string) $borderAttributes->LineStyle);
$thisBorder['borderStyle'] = self::BORDER_MAPPINGS['borderStyle'][$styleType] ?? BorderStyle::BORDER_NONE;
foreach ($borderAttributes as $borderStyleKey => $borderStyleValuex) {
$borderStyleValue = (string) $borderStyleValuex;
switch ($borderStyleKey) {
case 'Position':
[$borderPosition, $diagonalDirection]
= $this->parsePosition($borderStyleValue, $diagonalDirection);
break;
case 'Color':
$borderColour = substr($borderStyleValue, 1);
$thisBorder['color']['rgb'] = $borderColour;
break;
}
}
if ($borderPosition) {
$style['borders'][$borderPosition] = $thisBorder;
} elseif ($diagonalDirection) {
$style['borders']['diagonalDirection'] = $diagonalDirection;
$style['borders']['diagonal'] = $thisBorder;
}
}
return $style;
}
protected function parsePosition(string $borderStyleValue, string $diagonalDirection): array
{
$borderStyleValue = strtolower($borderStyleValue);
if (in_array($borderStyleValue, self::BORDER_POSITIONS)) {
$borderPosition = $borderStyleValue;
} elseif ($borderStyleValue === 'diagonalleft') {
$diagonalDirection = $diagonalDirection ? Borders::DIAGONAL_BOTH : Borders::DIAGONAL_DOWN;
} elseif ($borderStyleValue === 'diagonalright') {
$diagonalDirection = $diagonalDirection ? Borders::DIAGONAL_BOTH : Borders::DIAGONAL_UP;
}
return [$borderPosition ?? null, $diagonalDirection];
}
}

View file

@ -0,0 +1,63 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Reader\Xml\Style;
use PhpOffice\PhpSpreadsheet\Style\Fill as FillStyles;
use SimpleXMLElement;
class Fill extends StyleBase
{
/**
* @var array
*/
public const FILL_MAPPINGS = [
'fillType' => [
'solid' => FillStyles::FILL_SOLID,
'gray75' => FillStyles::FILL_PATTERN_DARKGRAY,
'gray50' => FillStyles::FILL_PATTERN_MEDIUMGRAY,
'gray25' => FillStyles::FILL_PATTERN_LIGHTGRAY,
'gray125' => FillStyles::FILL_PATTERN_GRAY125,
'gray0625' => FillStyles::FILL_PATTERN_GRAY0625,
'horzstripe' => FillStyles::FILL_PATTERN_DARKHORIZONTAL, // horizontal stripe
'vertstripe' => FillStyles::FILL_PATTERN_DARKVERTICAL, // vertical stripe
'reversediagstripe' => FillStyles::FILL_PATTERN_DARKUP, // reverse diagonal stripe
'diagstripe' => FillStyles::FILL_PATTERN_DARKDOWN, // diagonal stripe
'diagcross' => FillStyles::FILL_PATTERN_DARKGRID, // diagoanl crosshatch
'thickdiagcross' => FillStyles::FILL_PATTERN_DARKTRELLIS, // thick diagonal crosshatch
'thinhorzstripe' => FillStyles::FILL_PATTERN_LIGHTHORIZONTAL,
'thinvertstripe' => FillStyles::FILL_PATTERN_LIGHTVERTICAL,
'thinreversediagstripe' => FillStyles::FILL_PATTERN_LIGHTUP,
'thindiagstripe' => FillStyles::FILL_PATTERN_LIGHTDOWN,
'thinhorzcross' => FillStyles::FILL_PATTERN_LIGHTGRID, // thin horizontal crosshatch
'thindiagcross' => FillStyles::FILL_PATTERN_LIGHTTRELLIS, // thin diagonal crosshatch
],
];
public function parseStyle(SimpleXMLElement $styleAttributes): array
{
$style = [];
foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValuex) {
$styleAttributeValue = (string) $styleAttributeValuex;
switch ($styleAttributeKey) {
case 'Color':
$style['fill']['endColor']['rgb'] = substr($styleAttributeValue, 1);
$style['fill']['startColor']['rgb'] = substr($styleAttributeValue, 1);
break;
case 'PatternColor':
$style['fill']['startColor']['rgb'] = substr($styleAttributeValue, 1);
break;
case 'Pattern':
$lcStyleAttributeValue = strtolower((string) $styleAttributeValue);
$style['fill']['fillType']
= self::FILL_MAPPINGS['fillType'][$lcStyleAttributeValue] ?? FillStyles::FILL_NONE;
break;
}
}
return $style;
}
}

View file

@ -0,0 +1,79 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Reader\Xml\Style;
use PhpOffice\PhpSpreadsheet\Style\Font as FontUnderline;
use SimpleXMLElement;
class Font extends StyleBase
{
protected const UNDERLINE_STYLES = [
FontUnderline::UNDERLINE_NONE,
FontUnderline::UNDERLINE_DOUBLE,
FontUnderline::UNDERLINE_DOUBLEACCOUNTING,
FontUnderline::UNDERLINE_SINGLE,
FontUnderline::UNDERLINE_SINGLEACCOUNTING,
];
protected function parseUnderline(array $style, string $styleAttributeValue): array
{
if (self::identifyFixedStyleValue(self::UNDERLINE_STYLES, $styleAttributeValue)) {
$style['font']['underline'] = $styleAttributeValue;
}
return $style;
}
protected function parseVerticalAlign(array $style, string $styleAttributeValue): array
{
if ($styleAttributeValue == 'Superscript') {
$style['font']['superscript'] = true;
}
if ($styleAttributeValue == 'Subscript') {
$style['font']['subscript'] = true;
}
return $style;
}
public function parseStyle(SimpleXMLElement $styleAttributes): array
{
$style = [];
foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
$styleAttributeValue = (string) $styleAttributeValue;
switch ($styleAttributeKey) {
case 'FontName':
$style['font']['name'] = $styleAttributeValue;
break;
case 'Size':
$style['font']['size'] = $styleAttributeValue;
break;
case 'Color':
$style['font']['color']['rgb'] = substr($styleAttributeValue, 1);
break;
case 'Bold':
$style['font']['bold'] = $styleAttributeValue === '1';
break;
case 'Italic':
$style['font']['italic'] = $styleAttributeValue === '1';
break;
case 'Underline':
$style = $this->parseUnderline($style, $styleAttributeValue);
break;
case 'VerticalAlign':
$style = $this->parseVerticalAlign($style, $styleAttributeValue);
break;
}
}
return $style;
}
}

View file

@ -0,0 +1,33 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Reader\Xml\Style;
use SimpleXMLElement;
class NumberFormat extends StyleBase
{
public function parseStyle(SimpleXMLElement $styleAttributes): array
{
$style = [];
$fromFormats = ['\-', '\ '];
$toFormats = ['-', ' '];
foreach ($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
$styleAttributeValue = str_replace($fromFormats, $toFormats, $styleAttributeValue);
switch ($styleAttributeValue) {
case 'Short Date':
$styleAttributeValue = 'dd/mm/yyyy';
break;
}
if ($styleAttributeValue > '') {
$style['numberFormat']['formatCode'] = $styleAttributeValue;
}
}
return $style;
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Reader\Xml\Style;
use SimpleXMLElement;
abstract class StyleBase
{
protected static function identifyFixedStyleValue(array $styleList, string &$styleAttributeValue): bool
{
$returnValue = false;
$styleAttributeValue = strtolower($styleAttributeValue);
foreach ($styleList as $style) {
if ($styleAttributeValue == strtolower($style)) {
$styleAttributeValue = $style;
$returnValue = true;
break;
}
}
return $returnValue;
}
protected static function getAttributes(?SimpleXMLElement $simple, string $node): SimpleXMLElement
{
return ($simple === null) ? new SimpleXMLElement('<xml></xml>') : ($simple->attributes($node) ?? new SimpleXMLElement('<xml></xml>'));
}
}