提交的内容

This commit is contained in:
2025-05-12 15:45:02 +08:00
parent 629c4750da
commit b48c692775
3043 changed files with 34732 additions and 60810 deletions

56
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Spreadsheet.php vendored Executable file → Normal file
View File

@ -203,6 +203,14 @@ class Spreadsheet implements JsonSerializable
*/
private $tabRatio = 600;
/** @var Theme */
private $theme;
public function getTheme(): Theme
{
return $this->theme;
}
/**
* The workbook has macros ?
*
@ -476,6 +484,7 @@ class Spreadsheet implements JsonSerializable
{
$this->uniqueID = uniqid('', true);
$this->calculationEngine = new Calculation($this);
$this->theme = new Theme();
// Initialise worksheet collection and add one worksheet
$this->workSheetCollection = [];
@ -590,7 +599,7 @@ class Spreadsheet implements JsonSerializable
public function createSheet($sheetIndex = null)
{
$newSheet = new Worksheet($this);
$this->addSheet($newSheet, $sheetIndex);
$this->addSheet($newSheet, $sheetIndex, true);
return $newSheet;
}
@ -612,11 +621,24 @@ class Spreadsheet implements JsonSerializable
*
* @param Worksheet $worksheet The worksheet to add
* @param null|int $sheetIndex Index where sheet should go (0,1,..., or null for last)
* @param bool $retitleIfNeeded add suffix if title exists in spreadsheet
*
* @return Worksheet
*/
public function addSheet(Worksheet $worksheet, $sheetIndex = null)
public function addSheet(Worksheet $worksheet, $sheetIndex = null, $retitleIfNeeded = false)
{
if ($retitleIfNeeded) {
$title = $worksheet->getTitle();
if ($this->sheetNameExists($title)) {
$i = 1;
$newTitle = "$title $i";
while ($this->sheetNameExists($newTitle)) {
++$i;
$newTitle = "$title $i";
}
$worksheet->setTitle($newTitle);
}
}
if ($this->sheetNameExists($worksheet->getTitle())) {
throw new Exception(
"Workbook already contains a worksheet named '{$worksheet->getTitle()}'. Rename this worksheet first."
@ -741,13 +763,17 @@ class Spreadsheet implements JsonSerializable
*
* @return int index
*/
public function getIndex(Worksheet $worksheet)
public function getIndex(Worksheet $worksheet, bool $noThrow = false)
{
$wsHash = $worksheet->getHashInt();
foreach ($this->workSheetCollection as $key => $value) {
if ($value->getHashCode() === $worksheet->getHashCode()) {
if ($value->getHashInt() === $wsHash) {
return $key;
}
}
if ($noThrow) {
return -1;
}
throw new Exception('Sheet does not exist.');
}
@ -1654,4 +1680,26 @@ class Spreadsheet implements JsonSerializable
{
throw new Exception('Spreadsheet objects cannot be json encoded');
}
public function resetThemeFonts(): void
{
$majorFontLatin = $this->theme->getMajorFontLatin();
$minorFontLatin = $this->theme->getMinorFontLatin();
foreach ($this->cellXfCollection as $cellStyleXf) {
$scheme = $cellStyleXf->getFont()->getScheme();
if ($scheme === 'major') {
$cellStyleXf->getFont()->setName($majorFontLatin)->setScheme($scheme);
} elseif ($scheme === 'minor') {
$cellStyleXf->getFont()->setName($minorFontLatin)->setScheme($scheme);
}
}
foreach ($this->cellStyleXfCollection as $cellStyleXf) {
$scheme = $cellStyleXf->getFont()->getScheme();
if ($scheme === 'major') {
$cellStyleXf->getFont()->setName($majorFontLatin)->setScheme($scheme);
} elseif ($scheme === 'minor') {
$cellStyleXf->getFont()->setName($minorFontLatin)->setScheme($scheme);
}
}
}
}