Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).

- VSTACK and HSTACK. [Issue #4485](https://github.com/PHPOffice/PhpSpreadsheet/issues/4485) [PR #4492](https://github.com/PHPOffice/PhpSpreadsheet/pull/4492)
- TOCOL and TOROW. [PR #4493](https://github.com/PHPOffice/PhpSpreadsheet/pull/4493)
- Support Current Office Theme. [PR #4500](https://github.com/PHPOffice/PhpSpreadsheet/pull/4500)

### Removed

Expand All @@ -26,12 +27,15 @@ and this project adheres to [Semantic Versioning](https://semver.org).

### Deprecated

- Nothing yet.
- Theme constants COLOR_SCHEME_2013_PLUS_NAME (use COLOR_SCHEME_2013_2022_NAME) and COLOR_SCHEME_2013_PLUS (use COLOR_SCHEME_2013_2022).

### Fixed

- Various Writers RichText TextElement Should Inherit Cell Style. [Issue #1154](https://github.com/PHPOffice/PhpSpreadsheet/issues/1154) [PR #4487](https://github.com/PHPOffice/PhpSpreadsheet/pull/4487)
- Minor Changes to FILTER function. [PR #4491](https://github.com/PHPOffice/PhpSpreadsheet/pull/4491)
- Allow Xlsx Reader/Writer to support Font Charset. [Issue #2760](https://github.com/PHPOffice/PhpSpreadsheet/issues/2760) [PR #4501](https://github.com/PHPOffice/PhpSpreadsheet/pull/4501)
- AutoColor for LibreOffice Dark Mode [Discussion 4502](https://github.com/PHPOffice/PhpSpreadsheet/discussions/4502) [PR #4503](https://github.com/PHPOffice/PhpSpreadsheet/pull/4503)
- Xlsx Style Writer Minor Refactoring. [PR #4508](https://github.com/PHPOffice/PhpSpreadsheet/pull/4508)

## 2025-05-26 - 4.3.1

Expand Down
41 changes: 35 additions & 6 deletions src/PhpSpreadsheet/Writer/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,40 @@ public function getWriterPartWorksheet(): Worksheet
return $this->writerPartWorksheet;
}

public function createStyleDictionaries(): void
{
$this->styleHashTable->addFromSource(
$this->getWriterPartStyle()->allStyles(
$this->spreadSheet
)
);
$this->stylesConditionalHashTable->addFromSource(
$this->getWriterPartStyle()->allConditionalStyles(
$this->spreadSheet
)
);
$this->fillHashTable->addFromSource(
$this->getWriterPartStyle()->allFills(
$this->spreadSheet
)
);
$this->fontHashTable->addFromSource(
$this->getWriterPartStyle()->allFonts(
$this->spreadSheet
)
);
$this->bordersHashTable->addFromSource(
$this->getWriterPartStyle()->allBorders(
$this->spreadSheet
)
);
$this->numFmtHashTable->addFromSource(
$this->getWriterPartStyle()->allNumberFormats(
$this->spreadSheet
)
);
}

/**
* Save PhpSpreadsheet to file.
*
Expand All @@ -275,12 +309,7 @@ public function save($filename, int $flags = 0): void
}

// Create styles dictionaries
$this->styleHashTable->addFromSource($this->getWriterPartStyle()->allStyles($this->spreadSheet));
$this->stylesConditionalHashTable->addFromSource($this->getWriterPartStyle()->allConditionalStyles($this->spreadSheet));
$this->fillHashTable->addFromSource($this->getWriterPartStyle()->allFills($this->spreadSheet));
$this->fontHashTable->addFromSource($this->getWriterPartStyle()->allFonts($this->spreadSheet));
$this->bordersHashTable->addFromSource($this->getWriterPartStyle()->allBorders($this->spreadSheet));
$this->numFmtHashTable->addFromSource($this->getWriterPartStyle()->allNumberFormats($this->spreadSheet));
$this->createStyleDictionaries();

// Create drawing dictionary
$this->drawingHashTable->addFromSource($this->getWriterPartDrawing()->allDrawings($this->spreadSheet));
Expand Down
27 changes: 27 additions & 0 deletions tests/PhpSpreadsheetTests/Writer/Xlsx/StylesWriterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx;

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter;
use PHPUnit\Framework\TestCase;

class StylesWriterTest extends TestCase
{
public function testStylesWriter(): void
{
$spreadsheet = new Spreadsheet();

$writer = new XlsxWriter($spreadsheet);
$writer->createStyleDictionaries();
$writerStyle = new XlsxWriter\Style($writer);
$data = $writerStyle->writeStyles($spreadsheet);
self::assertStringContainsString(
'<fonts count="1"><font><b val="0"/><i val="0"/><strike val="0"/><u val="none"/><sz val="11"/><color rgb="FF000000"/><name val="Calibri"/></font></fonts>',
$data
);
$spreadsheet->disconnectWorksheets();
}
}