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,240 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Worksheet\Table;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Table;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class Column
{
/**
* Table Column Index.
*/
private string $columnIndex;
/**
* Show Filter Button.
*/
private bool $showFilterButton = true;
/**
* Total Row Label.
*/
private ?string $totalsRowLabel = null;
/**
* Total Row Function.
*/
private ?string $totalsRowFunction = null;
/**
* Total Row Formula.
*/
private ?string $totalsRowFormula = null;
/**
* Column Formula.
*/
private ?string $columnFormula = null;
/**
* Table.
*/
private ?Table $table;
/**
* Create a new Column.
*
* @param string $column Column (e.g. A)
* @param ?Table $table Table for this column
*/
public function __construct(string $column, ?Table $table = null)
{
$this->columnIndex = $column;
$this->table = $table;
}
/**
* Get Table column index as string eg: 'A'.
*/
public function getColumnIndex(): string
{
return $this->columnIndex;
}
/**
* Set Table column index as string eg: 'A'.
*
* @param string $column Column (e.g. A)
*/
public function setColumnIndex(string $column): self
{
// Uppercase coordinate
$column = strtoupper($column);
if ($this->table !== null) {
$this->table->isColumnInRange($column);
}
$this->columnIndex = $column;
return $this;
}
/**
* Get show Filter Button.
*/
public function getShowFilterButton(): bool
{
return $this->showFilterButton;
}
/**
* Set show Filter Button.
*/
public function setShowFilterButton(bool $showFilterButton): self
{
$this->showFilterButton = $showFilterButton;
return $this;
}
/**
* Get total Row Label.
*/
public function getTotalsRowLabel(): ?string
{
return $this->totalsRowLabel;
}
/**
* Set total Row Label.
*/
public function setTotalsRowLabel(string $totalsRowLabel): self
{
$this->totalsRowLabel = $totalsRowLabel;
return $this;
}
/**
* Get total Row Function.
*/
public function getTotalsRowFunction(): ?string
{
return $this->totalsRowFunction;
}
/**
* Set total Row Function.
*/
public function setTotalsRowFunction(string $totalsRowFunction): self
{
$this->totalsRowFunction = $totalsRowFunction;
return $this;
}
/**
* Get total Row Formula.
*/
public function getTotalsRowFormula(): ?string
{
return $this->totalsRowFormula;
}
/**
* Set total Row Formula.
*/
public function setTotalsRowFormula(string $totalsRowFormula): self
{
$this->totalsRowFormula = $totalsRowFormula;
return $this;
}
/**
* Get column Formula.
*/
public function getColumnFormula(): ?string
{
return $this->columnFormula;
}
/**
* Set column Formula.
*/
public function setColumnFormula(string $columnFormula): self
{
$this->columnFormula = $columnFormula;
return $this;
}
/**
* Get this Column's Table.
*/
public function getTable(): ?Table
{
return $this->table;
}
/**
* Set this Column's Table.
*/
public function setTable(?Table $table = null): self
{
$this->table = $table;
return $this;
}
public static function updateStructuredReferences(?Worksheet $workSheet, ?string $oldTitle, ?string $newTitle): void
{
if ($workSheet === null || $oldTitle === null || $oldTitle === '' || $newTitle === null) {
return;
}
// Remember that table headings are case-insensitive
if (StringHelper::strToLower($oldTitle) !== StringHelper::strToLower($newTitle)) {
// We need to check all formula cells that might contain Structured References that refer
// to this column, and update those formulae to reference the new column text
$spreadsheet = $workSheet->getParentOrThrow();
foreach ($spreadsheet->getWorksheetIterator() as $sheet) {
self::updateStructuredReferencesInCells($sheet, $oldTitle, $newTitle);
}
self::updateStructuredReferencesInNamedFormulae($spreadsheet, $oldTitle, $newTitle);
}
}
private static function updateStructuredReferencesInCells(Worksheet $worksheet, string $oldTitle, string $newTitle): void
{
$pattern = '/\[(@?)' . preg_quote($oldTitle, '/') . '\]/mui';
foreach ($worksheet->getCoordinates(false) as $coordinate) {
$cell = $worksheet->getCell($coordinate);
if ($cell->getDataType() === DataType::TYPE_FORMULA) {
$formula = $cell->getValue();
if (preg_match($pattern, $formula) === 1) {
$formula = preg_replace($pattern, "[$1{$newTitle}]", $formula);
$cell->setValueExplicit($formula, DataType::TYPE_FORMULA);
}
}
}
}
private static function updateStructuredReferencesInNamedFormulae(Spreadsheet $spreadsheet, string $oldTitle, string $newTitle): void
{
$pattern = '/\[(@?)' . preg_quote($oldTitle, '/') . '\]/mui';
foreach ($spreadsheet->getNamedFormulae() as $namedFormula) {
$formula = $namedFormula->getValue();
if (preg_match($pattern, $formula) === 1) {
$formula = preg_replace($pattern, "[$1{$newTitle}]", $formula);
$namedFormula->setValue($formula); // @phpstan-ignore-line
}
}
}
}

View file

@ -0,0 +1,218 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Worksheet\Table;
use PhpOffice\PhpSpreadsheet\Worksheet\Table;
class TableStyle
{
const TABLE_STYLE_NONE = '';
const TABLE_STYLE_LIGHT1 = 'TableStyleLight1';
const TABLE_STYLE_LIGHT2 = 'TableStyleLight2';
const TABLE_STYLE_LIGHT3 = 'TableStyleLight3';
const TABLE_STYLE_LIGHT4 = 'TableStyleLight4';
const TABLE_STYLE_LIGHT5 = 'TableStyleLight5';
const TABLE_STYLE_LIGHT6 = 'TableStyleLight6';
const TABLE_STYLE_LIGHT7 = 'TableStyleLight7';
const TABLE_STYLE_LIGHT8 = 'TableStyleLight8';
const TABLE_STYLE_LIGHT9 = 'TableStyleLight9';
const TABLE_STYLE_LIGHT10 = 'TableStyleLight10';
const TABLE_STYLE_LIGHT11 = 'TableStyleLight11';
const TABLE_STYLE_LIGHT12 = 'TableStyleLight12';
const TABLE_STYLE_LIGHT13 = 'TableStyleLight13';
const TABLE_STYLE_LIGHT14 = 'TableStyleLight14';
const TABLE_STYLE_LIGHT15 = 'TableStyleLight15';
const TABLE_STYLE_LIGHT16 = 'TableStyleLight16';
const TABLE_STYLE_LIGHT17 = 'TableStyleLight17';
const TABLE_STYLE_LIGHT18 = 'TableStyleLight18';
const TABLE_STYLE_LIGHT19 = 'TableStyleLight19';
const TABLE_STYLE_LIGHT20 = 'TableStyleLight20';
const TABLE_STYLE_LIGHT21 = 'TableStyleLight21';
const TABLE_STYLE_MEDIUM1 = 'TableStyleMedium1';
const TABLE_STYLE_MEDIUM2 = 'TableStyleMedium2';
const TABLE_STYLE_MEDIUM3 = 'TableStyleMedium3';
const TABLE_STYLE_MEDIUM4 = 'TableStyleMedium4';
const TABLE_STYLE_MEDIUM5 = 'TableStyleMedium5';
const TABLE_STYLE_MEDIUM6 = 'TableStyleMedium6';
const TABLE_STYLE_MEDIUM7 = 'TableStyleMedium7';
const TABLE_STYLE_MEDIUM8 = 'TableStyleMedium8';
const TABLE_STYLE_MEDIUM9 = 'TableStyleMedium9';
const TABLE_STYLE_MEDIUM10 = 'TableStyleMedium10';
const TABLE_STYLE_MEDIUM11 = 'TableStyleMedium11';
const TABLE_STYLE_MEDIUM12 = 'TableStyleMedium12';
const TABLE_STYLE_MEDIUM13 = 'TableStyleMedium13';
const TABLE_STYLE_MEDIUM14 = 'TableStyleMedium14';
const TABLE_STYLE_MEDIUM15 = 'TableStyleMedium15';
const TABLE_STYLE_MEDIUM16 = 'TableStyleMedium16';
const TABLE_STYLE_MEDIUM17 = 'TableStyleMedium17';
const TABLE_STYLE_MEDIUM18 = 'TableStyleMedium18';
const TABLE_STYLE_MEDIUM19 = 'TableStyleMedium19';
const TABLE_STYLE_MEDIUM20 = 'TableStyleMedium20';
const TABLE_STYLE_MEDIUM21 = 'TableStyleMedium21';
const TABLE_STYLE_MEDIUM22 = 'TableStyleMedium22';
const TABLE_STYLE_MEDIUM23 = 'TableStyleMedium23';
const TABLE_STYLE_MEDIUM24 = 'TableStyleMedium24';
const TABLE_STYLE_MEDIUM25 = 'TableStyleMedium25';
const TABLE_STYLE_MEDIUM26 = 'TableStyleMedium26';
const TABLE_STYLE_MEDIUM27 = 'TableStyleMedium27';
const TABLE_STYLE_MEDIUM28 = 'TableStyleMedium28';
const TABLE_STYLE_DARK1 = 'TableStyleDark1';
const TABLE_STYLE_DARK2 = 'TableStyleDark2';
const TABLE_STYLE_DARK3 = 'TableStyleDark3';
const TABLE_STYLE_DARK4 = 'TableStyleDark4';
const TABLE_STYLE_DARK5 = 'TableStyleDark5';
const TABLE_STYLE_DARK6 = 'TableStyleDark6';
const TABLE_STYLE_DARK7 = 'TableStyleDark7';
const TABLE_STYLE_DARK8 = 'TableStyleDark8';
const TABLE_STYLE_DARK9 = 'TableStyleDark9';
const TABLE_STYLE_DARK10 = 'TableStyleDark10';
const TABLE_STYLE_DARK11 = 'TableStyleDark11';
/**
* Theme.
*/
private string $theme;
/**
* Show First Column.
*/
private bool $showFirstColumn = false;
/**
* Show Last Column.
*/
private bool $showLastColumn = false;
/**
* Show Row Stripes.
*/
private bool $showRowStripes = false;
/**
* Show Column Stripes.
*/
private bool $showColumnStripes = false;
/**
* Table.
*/
private ?Table $table = null;
/**
* Create a new Table Style.
*
* @param string $theme (e.g. TableStyle::TABLE_STYLE_MEDIUM2)
*/
public function __construct(string $theme = self::TABLE_STYLE_MEDIUM2)
{
$this->theme = $theme;
}
/**
* Get theme.
*/
public function getTheme(): string
{
return $this->theme;
}
/**
* Set theme.
*/
public function setTheme(string $theme): self
{
$this->theme = $theme;
return $this;
}
/**
* Get show First Column.
*/
public function getShowFirstColumn(): bool
{
return $this->showFirstColumn;
}
/**
* Set show First Column.
*/
public function setShowFirstColumn(bool $showFirstColumn): self
{
$this->showFirstColumn = $showFirstColumn;
return $this;
}
/**
* Get show Last Column.
*/
public function getShowLastColumn(): bool
{
return $this->showLastColumn;
}
/**
* Set show Last Column.
*/
public function setShowLastColumn(bool $showLastColumn): self
{
$this->showLastColumn = $showLastColumn;
return $this;
}
/**
* Get show Row Stripes.
*/
public function getShowRowStripes(): bool
{
return $this->showRowStripes;
}
/**
* Set show Row Stripes.
*/
public function setShowRowStripes(bool $showRowStripes): self
{
$this->showRowStripes = $showRowStripes;
return $this;
}
/**
* Get show Column Stripes.
*/
public function getShowColumnStripes(): bool
{
return $this->showColumnStripes;
}
/**
* Set show Column Stripes.
*/
public function setShowColumnStripes(bool $showColumnStripes): self
{
$this->showColumnStripes = $showColumnStripes;
return $this;
}
/**
* Get this Style's Table.
*/
public function getTable(): ?Table
{
return $this->table;
}
/**
* Set this Style's Table.
*/
public function setTable(?Table $table = null): self
{
$this->table = $table;
return $this;
}
}