diff --git a/src/FastExcelWriter/Excel.php b/src/FastExcelWriter/Excel.php index ef1e5e3..4d12c0b 100644 --- a/src/FastExcelWriter/Excel.php +++ b/src/FastExcelWriter/Excel.php @@ -1642,6 +1642,62 @@ public function output(string $name = null) { $this->download($name); } + + public function getDefaultStyle(): array + { + return $this->style->getDefaultStyle(); + } + + public function getHyperlinkStyle(): array + { + return $this->style->getHyperlinkStyle(); + } + + public function getDefaultFormatStyles(): array + { + return $this->style->getDefaultFormatStyles(); + } + + public function getStyleLocaleSettings(): array + { + return $this->style->getLocaleSettings(); + } + + public function getStyleFonts(): array + { + return $this->style->getStyleFonts(); + } + + public function getStyleFills(): array + { + return $this->style->getStyleFonts(); + } + + public function getStyleBorders(): array + { + return $this->style->getStyleBorders(); + } + + public function getStyleCellXfs(): array + { + return $this->style->getStyleCellXfs(); + } + + public function getStyleIndexedColors(): array + { + return $this->style->getIndexedColors(); + } + + public function addStyle($cellStyle, &$resultStyle): array + { + return $this->style->addStyle($cellStyle, $resultStyle); + } + + public function getStyleNumberFormats(): array + { + return $this->style->_getNumberFormats(); + } + } // EOF diff --git a/src/FastExcelWriter/Sheet.php b/src/FastExcelWriter/Sheet.php index 5af9f3d..ee05e07 100644 --- a/src/FastExcelWriter/Sheet.php +++ b/src/FastExcelWriter/Sheet.php @@ -1472,14 +1472,14 @@ protected function _writeRow(?Writer $writer, array $row = [], array $rowOptions if (empty($this->sheetStylesSummary)) { if ($this->defaultStyle) { $this->sheetStylesSummary = [ - 'general_style' => Style::mergeStyles([$this->excel->style->defaultStyle, $this->defaultStyle]), - 'hyperlink_style' => Style::mergeStyles([$this->excel->style->hyperlinkStyle, $this->defaultStyle]), + 'general_style' => Style::mergeStyles([$this->excel->getDefaultStyle(), $this->defaultStyle]), + 'hyperlink_style' => Style::mergeStyles([$this->excel->getHyperlinkStyle(), $this->defaultStyle]), ]; } else { $this->sheetStylesSummary = [ - 'general_style' => $this->excel->style->defaultStyle, - 'hyperlink_style' => $this->excel->style->hyperlinkStyle, + 'general_style' => $this->excel->getDefaultStyle(), + 'hyperlink_style' => $this->excel->getHyperlinkStyle(), ]; } } @@ -1534,8 +1534,8 @@ protected function _writeRow(?Writer $writer, array $row = [], array $rowOptions else { $cellStyle = $styleStack ? $styleStack[0] : []; } - if (!empty($cellStyle['format']['format-pattern']) && !empty($this->excel->style->defaultFormatStyles[$cellStyle['format']['format-pattern']])) { - $cellStyle = Style::mergeStyles([$this->excel->style->defaultFormatStyles[$cellStyle['format']['format-pattern']], $cellStyle]); + if (!empty($cellStyle['format']['format-pattern']) && !empty($this->excel->getDefaultFormatStyles()[$cellStyle['format']['format-pattern']])) { + $cellStyle = Style::mergeStyles([$this->excel->getDefaultFormatStyles()[$cellStyle['format']['format-pattern']], $cellStyle]); } if (isset($cellStyle['hyperlink'])) { @@ -1551,8 +1551,8 @@ protected function _writeRow(?Writer $writer, array $row = [], array $rowOptions 'shared_index' => $this->excel->addSharedString($cellValue), ]; $this->_addExternalLink(Excel::cellAddress($rowIdx + 1, $colIdx + 1), $link); - if (!empty($this->excel->style->hyperlinkStyle)) { - $cellStyle = Style::mergeStyles([$this->excel->style->hyperlinkStyle, $cellStyle]); + if (!empty($this->excel->getHyperlinkStyle())) { + $cellStyle = Style::mergeStyles([$this->excel->getHyperlinkStyle(), $cellStyle]); } } unset($cellStyle['hyperlink']); @@ -1560,7 +1560,7 @@ protected function _writeRow(?Writer $writer, array $row = [], array $rowOptions $styleHash = $cellStyle ? json_encode($cellStyle) : ''; if (!isset($_styleCache[$styleHash])) { - $cellStyleIdx = $this->excel->style->addStyle($cellStyle, $resultStyle); + $cellStyleIdx = $this->excel->addStyle($cellStyle, $resultStyle); $_styleCache[$styleHash] = ['cell_style' => $cellStyle, 'result_style' => $resultStyle, 'style_idx' => $cellStyleIdx]; } else { diff --git a/src/FastExcelWriter/Style.php b/src/FastExcelWriter/Style.php index 2fe4746..6d5ea70 100644 --- a/src/FastExcelWriter/Style.php +++ b/src/FastExcelWriter/Style.php @@ -86,20 +86,20 @@ class Style protected static $instance; - public array $localeSettings = []; + protected array $localeSettings = []; public array $defaultFont = []; protected int $defaultFontId = -1; - public array $defaultStyle = []; + protected array $defaultStyle = []; /** @var array Specified styles for hyperlinks */ - public array $hyperlinkStyle = []; + protected array $hyperlinkStyle = []; /** @var array Specified styles for formats '@...' */ - public array $defaultFormatStyles = []; + protected array $defaultFormatStyles = []; - public array $indexedColors = ['00000000', + protected array $indexedColors = ['00000000', '00FFFFFF', '00FF0000', '0000FF00', '000000FF', '00FFFF00', '00FF00FF', '0000FFFF', '00000000', '00FFFFFF', '00FF0000', '0000FF00', '000000FF', '00FFFF00', '00FF00FF', '0000FFFF', '00800000', '00008000', '00000080', '00808000', '00800080', '00008080', '00C0C0C0', '00808080', '009999FF', '00993366', '00FFFFCC', '00CCFFFF', @@ -1606,6 +1606,30 @@ public function _getNumberFormats(): array } return []; } + + public function getDefaultStyle(): array + { + return $this->defaultStyle; + } + public function getHyperlinkStyle(): array + { + return $this->hyperlinkStyle; + } + + public function getDefaultFormatStyles(): array + { + return $this->defaultFormatStyles; + } + + public function getLocaleSettings(): array + { + return $this->localeSettings; + } + + public function getIndexedColors(): array + { + return $this->indexedColors; + } } // EOF diff --git a/src/FastExcelWriter/Writer/Writer.php b/src/FastExcelWriter/Writer/Writer.php index 4684e39..64ace0f 100644 --- a/src/FastExcelWriter/Writer/Writer.php +++ b/src/FastExcelWriter/Writer/Writer.php @@ -1282,11 +1282,11 @@ protected function _convertFormula($formula, $baseAddress): string return $matches[0]; }, $formula); - if (!empty($this->excel->style->localeSettings['functions']) && strpos($formula, '(')) { + if (!empty($this->excel->getStyleLocaleSettings()['functions']) && strpos($formula, '(')) { // replace national function names if (empty($functionNames)) { $functionNames = [[], []]; - foreach ($this->excel->style->localeSettings['functions'] as $name => $nameEn) { + foreach ($this->excel->getStyleLocaleSettings()['functions'] as $name => $nameEn) { $functionNames[0][] = '/' . $name . '\s*\(/ui'; $functionNames[1][] = $nameEn . '('; if ($nameEn === 'FALSE' || $nameEn === 'TRUE') { @@ -1482,7 +1482,7 @@ protected function _writeStylesXML() //// +++++++++++ //// - $numberFormats = $this->excel->style->_getNumberFormats(); + $numberFormats = $this->excel->getStyleNumberFormats(); if (!$numberFormats) { $file->write(''); } else { @@ -1495,7 +1495,7 @@ protected function _writeStylesXML() //// +++++++++++ //// - $fonts = $this->excel->style->getStyleFonts(); + $fonts = $this->excel->getStyleFonts(); if (!$fonts) { $file->write(''); } @@ -1511,7 +1511,7 @@ protected function _writeStylesXML() //// +++++++++++ //// - $fills = $this->excel->style->getStyleFills(); + $fills = $this->excel->getStyleFills(); if (!$fills) { $file->write(''); } @@ -1525,7 +1525,7 @@ protected function _writeStylesXML() //// +++++++++++ // - $borders = $this->excel->style->getStyleBorders(); + $borders = $this->excel->getStyleBorders(); if (!$borders) { $file->write(''); } @@ -1550,7 +1550,7 @@ protected function _writeStylesXML() //// +++++++++++ // - $cellXfs = $this->excel->style->getStyleCellXfs(); + $cellXfs = $this->excel->getStyleCellXfs(); if (!$cellXfs) { $file->write(''); $file->write(''); @@ -1640,9 +1640,9 @@ protected function _writeStylesXML() // $file->write(''); - if ($this->excel->style->indexedColors) { + if ($this->excel->getStyleIndexedColors()) { $file->write(''); - foreach ($this->excel->style->indexedColors as $color) { + foreach ($this->excel->getStyleIndexedColors() as $color) { $file->write(''); } $file->write('');