init commit

This commit is contained in:
2026-03-17 09:56:00 +08:00
commit e2c8ae752d
6827 changed files with 1211784 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting;
class ConditionalDataBar
{
/** <dataBar> attribute */
/** @var null|bool */
private $showValue;
/** <dataBar> children */
/** @var ConditionalFormatValueObject */
private $minimumConditionalFormatValueObject;
/** @var ConditionalFormatValueObject */
private $maximumConditionalFormatValueObject;
/** @var string */
private $color;
/** <extLst> */
/** @var ConditionalFormattingRuleExtension */
private $conditionalFormattingRuleExt;
/**
* @return null|bool
*/
public function getShowValue()
{
return $this->showValue;
}
/**
* @param bool $showValue
*/
public function setShowValue($showValue)
{
$this->showValue = $showValue;
return $this;
}
/**
* @return ConditionalFormatValueObject
*/
public function getMinimumConditionalFormatValueObject()
{
return $this->minimumConditionalFormatValueObject;
}
public function setMinimumConditionalFormatValueObject(ConditionalFormatValueObject $minimumConditionalFormatValueObject)
{
$this->minimumConditionalFormatValueObject = $minimumConditionalFormatValueObject;
return $this;
}
/**
* @return ConditionalFormatValueObject
*/
public function getMaximumConditionalFormatValueObject()
{
return $this->maximumConditionalFormatValueObject;
}
public function setMaximumConditionalFormatValueObject(ConditionalFormatValueObject $maximumConditionalFormatValueObject)
{
$this->maximumConditionalFormatValueObject = $maximumConditionalFormatValueObject;
return $this;
}
public function getColor(): string
{
return $this->color;
}
public function setColor(string $color): self
{
$this->color = $color;
return $this;
}
/**
* @return ConditionalFormattingRuleExtension
*/
public function getConditionalFormattingRuleExt()
{
return $this->conditionalFormattingRuleExt;
}
public function setConditionalFormattingRuleExt(ConditionalFormattingRuleExtension $conditionalFormattingRuleExt)
{
$this->conditionalFormattingRuleExt = $conditionalFormattingRuleExt;
return $this;
}
}

View File

@@ -0,0 +1,290 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting;
class ConditionalDataBarExtension
{
/** <dataBar> attributes */
/** @var int */
private $minLength;
/** @var int */
private $maxLength;
/** @var null|bool */
private $border;
/** @var null|bool */
private $gradient;
/** @var string */
private $direction;
/** @var null|bool */
private $negativeBarBorderColorSameAsPositive;
/** @var string */
private $axisPosition;
// <dataBar> children
/** @var ConditionalFormatValueObject */
private $maximumConditionalFormatValueObject;
/** @var ConditionalFormatValueObject */
private $minimumConditionalFormatValueObject;
/** @var string */
private $borderColor;
/** @var string */
private $negativeFillColor;
/** @var string */
private $negativeBorderColor;
/** @var array */
private $axisColor = [
'rgb' => null,
'theme' => null,
'tint' => null,
];
public function getXmlAttributes()
{
$ret = [];
foreach (['minLength', 'maxLength', 'direction', 'axisPosition'] as $attrKey) {
if (null !== $this->{$attrKey}) {
$ret[$attrKey] = $this->{$attrKey};
}
}
foreach (['border', 'gradient', 'negativeBarBorderColorSameAsPositive'] as $attrKey) {
if (null !== $this->{$attrKey}) {
$ret[$attrKey] = $this->{$attrKey} ? '1' : '0';
}
}
return $ret;
}
public function getXmlElements()
{
$ret = [];
$elms = ['borderColor', 'negativeFillColor', 'negativeBorderColor'];
foreach ($elms as $elmKey) {
if (null !== $this->{$elmKey}) {
$ret[$elmKey] = ['rgb' => $this->{$elmKey}];
}
}
foreach (array_filter($this->axisColor) as $attrKey => $axisColorAttr) {
if (!isset($ret['axisColor'])) {
$ret['axisColor'] = [];
}
$ret['axisColor'][$attrKey] = $axisColorAttr;
}
return $ret;
}
/**
* @return int
*/
public function getMinLength()
{
return $this->minLength;
}
public function setMinLength(int $minLength): self
{
$this->minLength = $minLength;
return $this;
}
/**
* @return int
*/
public function getMaxLength()
{
return $this->maxLength;
}
public function setMaxLength(int $maxLength): self
{
$this->maxLength = $maxLength;
return $this;
}
/**
* @return null|bool
*/
public function getBorder()
{
return $this->border;
}
public function setBorder(bool $border): self
{
$this->border = $border;
return $this;
}
/**
* @return null|bool
*/
public function getGradient()
{
return $this->gradient;
}
public function setGradient(bool $gradient): self
{
$this->gradient = $gradient;
return $this;
}
/**
* @return string
*/
public function getDirection()
{
return $this->direction;
}
public function setDirection(string $direction): self
{
$this->direction = $direction;
return $this;
}
/**
* @return null|bool
*/
public function getNegativeBarBorderColorSameAsPositive()
{
return $this->negativeBarBorderColorSameAsPositive;
}
public function setNegativeBarBorderColorSameAsPositive(bool $negativeBarBorderColorSameAsPositive): self
{
$this->negativeBarBorderColorSameAsPositive = $negativeBarBorderColorSameAsPositive;
return $this;
}
/**
* @return string
*/
public function getAxisPosition()
{
return $this->axisPosition;
}
public function setAxisPosition(string $axisPosition): self
{
$this->axisPosition = $axisPosition;
return $this;
}
/**
* @return ConditionalFormatValueObject
*/
public function getMaximumConditionalFormatValueObject()
{
return $this->maximumConditionalFormatValueObject;
}
public function setMaximumConditionalFormatValueObject(ConditionalFormatValueObject $maximumConditionalFormatValueObject)
{
$this->maximumConditionalFormatValueObject = $maximumConditionalFormatValueObject;
return $this;
}
/**
* @return ConditionalFormatValueObject
*/
public function getMinimumConditionalFormatValueObject()
{
return $this->minimumConditionalFormatValueObject;
}
public function setMinimumConditionalFormatValueObject(ConditionalFormatValueObject $minimumConditionalFormatValueObject)
{
$this->minimumConditionalFormatValueObject = $minimumConditionalFormatValueObject;
return $this;
}
/**
* @return string
*/
public function getBorderColor()
{
return $this->borderColor;
}
public function setBorderColor(string $borderColor): self
{
$this->borderColor = $borderColor;
return $this;
}
/**
* @return string
*/
public function getNegativeFillColor()
{
return $this->negativeFillColor;
}
public function setNegativeFillColor(string $negativeFillColor): self
{
$this->negativeFillColor = $negativeFillColor;
return $this;
}
/**
* @return string
*/
public function getNegativeBorderColor()
{
return $this->negativeBorderColor;
}
public function setNegativeBorderColor(string $negativeBorderColor): self
{
$this->negativeBorderColor = $negativeBorderColor;
return $this;
}
public function getAxisColor(): array
{
return $this->axisColor;
}
/**
* @param mixed $rgb
* @param null|mixed $theme
* @param null|mixed $tint
*/
public function setAxisColor($rgb, $theme = null, $tint = null): self
{
$this->axisColor = [
'rgb' => $rgb,
'theme' => $theme,
'tint' => $tint,
];
return $this;
}
}

View File

@@ -0,0 +1,78 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting;
class ConditionalFormatValueObject
{
private $type;
private $value;
private $cellFormula;
/**
* ConditionalFormatValueObject constructor.
*
* @param null|mixed $cellFormula
*/
public function __construct($type, $value = null, $cellFormula = null)
{
$this->type = $type;
$this->value = $value;
$this->cellFormula = $cellFormula;
}
/**
* @return mixed
*/
public function getType()
{
return $this->type;
}
/**
* @param mixed $type
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* @return mixed
*/
public function getValue()
{
return $this->value;
}
/**
* @param mixed $value
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* @return mixed
*/
public function getCellFormula()
{
return $this->cellFormula;
}
/**
* @param mixed $cellFormula
*/
public function setCellFormula($cellFormula)
{
$this->cellFormula = $cellFormula;
return $this;
}
}

View File

@@ -0,0 +1,208 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting;
use PhpOffice\PhpSpreadsheet\Style\Conditional;
use SimpleXMLElement;
class ConditionalFormattingRuleExtension
{
const CONDITION_EXTENSION_DATABAR = 'dataBar';
/** <conditionalFormatting> attributes */
private $id;
/** @var string Conditional Formatting Rule */
private $cfRule;
/** <conditionalFormatting> children */
/** @var ConditionalDataBarExtension */
private $dataBar;
/** @var string Sequence of References */
private $sqref;
/**
* ConditionalFormattingRuleExtension constructor.
*/
public function __construct($id = null, string $cfRule = self::CONDITION_EXTENSION_DATABAR)
{
if (null === $id) {
$this->id = '{' . $this->generateUuid() . '}';
} else {
$this->id = $id;
}
$this->cfRule = $cfRule;
}
private function generateUuid()
{
$chars = str_split('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx');
foreach ($chars as $i => $char) {
if ($char === 'x') {
$chars[$i] = dechex(random_int(0, 15));
} elseif ($char === 'y') {
$chars[$i] = dechex(random_int(8, 11));
}
}
return implode('', $chars);
}
public static function parseExtLstXml($extLstXml)
{
$conditionalFormattingRuleExtensions = [];
$conditionalFormattingRuleExtensionXml = null;
if ($extLstXml instanceof SimpleXMLElement) {
foreach ((count($extLstXml) > 0 ? $extLstXml : [$extLstXml]) as $extLst) {
//this uri is conditionalFormattings
//https://docs.microsoft.com/en-us/openspecs/office_standards/ms-xlsx/07d607af-5618-4ca2-b683-6a78dc0d9627
if (isset($extLst->ext['uri']) && (string) $extLst->ext['uri'] === '{78C0D931-6437-407d-A8EE-F0AAD7539E65}') {
$conditionalFormattingRuleExtensionXml = $extLst->ext;
}
}
if ($conditionalFormattingRuleExtensionXml) {
$ns = $conditionalFormattingRuleExtensionXml->getNamespaces(true);
$extFormattingsXml = $conditionalFormattingRuleExtensionXml->children($ns['x14']);
foreach ($extFormattingsXml->children($ns['x14']) as $extFormattingXml) {
$extCfRuleXml = $extFormattingXml->cfRule;
$attributes = $extCfRuleXml->attributes();
if (!$attributes || ((string) $attributes->type) !== Conditional::CONDITION_DATABAR) {
continue;
}
$extFormattingRuleObj = new self((string) $attributes->id);
$extFormattingRuleObj->setSqref((string) $extFormattingXml->children($ns['xm'])->sqref);
$conditionalFormattingRuleExtensions[$extFormattingRuleObj->getId()] = $extFormattingRuleObj;
$extDataBarObj = new ConditionalDataBarExtension();
$extFormattingRuleObj->setDataBarExt($extDataBarObj);
$dataBarXml = $extCfRuleXml->dataBar;
self::parseExtDataBarAttributesFromXml($extDataBarObj, $dataBarXml);
self::parseExtDataBarElementChildrenFromXml($extDataBarObj, $dataBarXml, $ns);
}
}
}
return $conditionalFormattingRuleExtensions;
}
private static function parseExtDataBarAttributesFromXml(
ConditionalDataBarExtension $extDataBarObj,
SimpleXMLElement $dataBarXml
): void {
$dataBarAttribute = $dataBarXml->attributes();
if ($dataBarAttribute->minLength) {
$extDataBarObj->setMinLength((int) $dataBarAttribute->minLength);
}
if ($dataBarAttribute->maxLength) {
$extDataBarObj->setMaxLength((int) $dataBarAttribute->maxLength);
}
if ($dataBarAttribute->border) {
$extDataBarObj->setBorder((bool) (string) $dataBarAttribute->border);
}
if ($dataBarAttribute->gradient) {
$extDataBarObj->setGradient((bool) (string) $dataBarAttribute->gradient);
}
if ($dataBarAttribute->direction) {
$extDataBarObj->setDirection((string) $dataBarAttribute->direction);
}
if ($dataBarAttribute->negativeBarBorderColorSameAsPositive) {
$extDataBarObj->setNegativeBarBorderColorSameAsPositive((bool) (string) $dataBarAttribute->negativeBarBorderColorSameAsPositive);
}
if ($dataBarAttribute->axisPosition) {
$extDataBarObj->setAxisPosition((string) $dataBarAttribute->axisPosition);
}
}
private static function parseExtDataBarElementChildrenFromXml(ConditionalDataBarExtension $extDataBarObj, SimpleXMLElement $dataBarXml, $ns): void
{
if ($dataBarXml->borderColor) {
$extDataBarObj->setBorderColor((string) $dataBarXml->borderColor->attributes()['rgb']);
}
if ($dataBarXml->negativeFillColor) {
$extDataBarObj->setNegativeFillColor((string) $dataBarXml->negativeFillColor->attributes()['rgb']);
}
if ($dataBarXml->negativeBorderColor) {
$extDataBarObj->setNegativeBorderColor((string) $dataBarXml->negativeBorderColor->attributes()['rgb']);
}
if ($dataBarXml->axisColor) {
$axisColorAttr = $dataBarXml->axisColor->attributes();
$extDataBarObj->setAxisColor((string) $axisColorAttr['rgb'], (string) $axisColorAttr['theme'], (string) $axisColorAttr['tint']);
}
$cfvoIndex = 0;
foreach ($dataBarXml->cfvo as $cfvo) {
$f = (string) $cfvo->children($ns['xm'])->f;
$attributes = $cfvo->attributes();
if (!($attributes)) {
continue;
}
if ($cfvoIndex === 0) {
$extDataBarObj->setMinimumConditionalFormatValueObject(new ConditionalFormatValueObject((string) $attributes['type'], null, (empty($f) ? null : $f)));
}
if ($cfvoIndex === 1) {
$extDataBarObj->setMaximumConditionalFormatValueObject(new ConditionalFormatValueObject((string) $attributes['type'], null, (empty($f) ? null : $f)));
}
++$cfvoIndex;
}
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
*/
public function setId($id): self
{
$this->id = $id;
return $this;
}
public function getCfRule(): string
{
return $this->cfRule;
}
public function setCfRule(string $cfRule): self
{
$this->cfRule = $cfRule;
return $this;
}
public function getDataBarExt(): ConditionalDataBarExtension
{
return $this->dataBar;
}
public function setDataBarExt(ConditionalDataBarExtension $dataBar): self
{
$this->dataBar = $dataBar;
return $this;
}
public function getSqref(): string
{
return $this->sqref;
}
public function setSqref(string $sqref): self
{
$this->sqref = $sqref;
return $this;
}
}