Skip to content

Commit

Permalink
Merge pull request #79 from timshaq/grasp
Browse files Browse the repository at this point in the history
GRASP - Information Expert
  • Loading branch information
aVadim483 authored Sep 7, 2024
2 parents 7bb81b9 + 417e1f1 commit d5464fb
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 23 deletions.
56 changes: 56 additions & 0 deletions src/FastExcelWriter/Excel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 9 additions & 9 deletions src/FastExcelWriter/Sheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
}
}
Expand Down Expand Up @@ -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'])) {
Expand All @@ -1551,16 +1551,16 @@ 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']);
}

$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 {
Expand Down
34 changes: 29 additions & 5 deletions src/FastExcelWriter/Style.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
18 changes: 9 additions & 9 deletions src/FastExcelWriter/Writer/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -1482,7 +1482,7 @@ protected function _writeStylesXML()

//// +++++++++++
//// <numFmts/>
$numberFormats = $this->excel->style->_getNumberFormats();
$numberFormats = $this->excel->getStyleNumberFormats();
if (!$numberFormats) {
$file->write('<numFmts count="0"/>');
} else {
Expand All @@ -1495,7 +1495,7 @@ protected function _writeStylesXML()

//// +++++++++++
//// <fonts/>
$fonts = $this->excel->style->getStyleFonts();
$fonts = $this->excel->getStyleFonts();
if (!$fonts) {
$file->write('<fonts count="0"/>');
}
Expand All @@ -1511,7 +1511,7 @@ protected function _writeStylesXML()

//// +++++++++++
//// <fills/>
$fills = $this->excel->style->getStyleFills();
$fills = $this->excel->getStyleFills();
if (!$fills) {
$file->write('<fills count="0"/>');
}
Expand All @@ -1525,7 +1525,7 @@ protected function _writeStylesXML()

//// +++++++++++
// <borders/>
$borders = $this->excel->style->getStyleBorders();
$borders = $this->excel->getStyleBorders();
if (!$borders) {
$file->write('<borders count="0"/>');
}
Expand All @@ -1550,7 +1550,7 @@ protected function _writeStylesXML()

//// +++++++++++
// <cellXfs/>
$cellXfs = $this->excel->style->getStyleCellXfs();
$cellXfs = $this->excel->getStyleCellXfs();
if (!$cellXfs) {
$file->write('<cellXfs count="1">');
$file->write('<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>');
Expand Down Expand Up @@ -1640,9 +1640,9 @@ protected function _writeStylesXML()
// <tableStyles/>
$file->write('<tableStyles count="0"/>');

if ($this->excel->style->indexedColors) {
if ($this->excel->getStyleIndexedColors()) {
$file->write('<colors><indexedColors>');
foreach ($this->excel->style->indexedColors as $color) {
foreach ($this->excel->getStyleIndexedColors() as $color) {
$file->write('<rgbColor rgb="' . $color . '"/>');
}
$file->write('</indexedColors></colors>');
Expand Down

0 comments on commit d5464fb

Please sign in to comment.