Begin optimize xlsx write
This commit is contained in:
parent
91f756be0b
commit
57b6e87a65
7
src/Spout/Common/Entity/Style/EmptyStyle.php
Normal file
7
src/Spout/Common/Entity/Style/EmptyStyle.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Common\Entity\Style;
|
||||
|
||||
class EmptyStyle extends Style
|
||||
{
|
||||
}
|
@ -36,7 +36,7 @@ class StyleRegistry
|
||||
{
|
||||
$serializedStyle = $this->serialize($style);
|
||||
|
||||
if (!$this->hasStyleAlreadyBeenRegistered($style)) {
|
||||
if (!$this->hasSerializedStyleAlreadyBeenRegistered($serializedStyle)) {
|
||||
$nextStyleId = \count($this->serializedStyleToStyleIdMappingTable);
|
||||
$style->setId($nextStyleId);
|
||||
|
||||
@ -57,6 +57,17 @@ class StyleRegistry
|
||||
{
|
||||
$serializedStyle = $this->serialize($style);
|
||||
|
||||
return $this->hasSerializedStyleAlreadyBeenRegistered($serializedStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the serialized style has already been registered.
|
||||
*
|
||||
* @param string $serializedStyle The serialized style
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasSerializedStyleAlreadyBeenRegistered(string $serializedStyle)
|
||||
{
|
||||
// Using isset here because it is way faster than array_key_exists...
|
||||
return isset($this->serializedStyleToStyleIdMappingTable[$serializedStyle]);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ namespace Box\Spout\Writer\ODS\Manager;
|
||||
|
||||
use Box\Spout\Common\Entity\Cell;
|
||||
use Box\Spout\Common\Entity\Row;
|
||||
use Box\Spout\Common\Entity\Style\EmptyStyle;
|
||||
use Box\Spout\Common\Entity\Style\Style;
|
||||
use Box\Spout\Common\Exception\InvalidArgumentException;
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
@ -157,9 +158,13 @@ class WorksheetManager implements WorksheetManagerInterface
|
||||
*/
|
||||
private function applyStyleAndGetCellXML(Cell $cell, Style $rowStyle, $currentCellIndex, $nextCellIndex)
|
||||
{
|
||||
// Apply row and extra styles
|
||||
$mergedCellAndRowStyle = $this->styleMerger->merge($cell->getStyle(), $rowStyle);
|
||||
$cell->setStyle($mergedCellAndRowStyle);
|
||||
if ($cell->getStyle() instanceof EmptyStyle) {
|
||||
$cell->setStyle($rowStyle);
|
||||
} else {
|
||||
$mergedCellAndRowStyle = $this->styleMerger->merge($cell->getStyle(), $rowStyle);
|
||||
$cell->setStyle($mergedCellAndRowStyle);
|
||||
}
|
||||
|
||||
$newCellStyle = $this->styleManager->applyExtraStylesIfNeeded($cell);
|
||||
|
||||
$registeredStyle = $this->styleManager->registerStyle($newCellStyle);
|
||||
|
@ -4,6 +4,7 @@ namespace Box\Spout\Writer\XLSX\Manager;
|
||||
|
||||
use Box\Spout\Common\Entity\Cell;
|
||||
use Box\Spout\Common\Entity\Row;
|
||||
use Box\Spout\Common\Entity\Style\EmptyStyle;
|
||||
use Box\Spout\Common\Entity\Style\Style;
|
||||
use Box\Spout\Common\Exception\InvalidArgumentException;
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
@ -185,11 +186,14 @@ EOD;
|
||||
*/
|
||||
private function applyStyleAndGetCellXML(Cell $cell, Style $rowStyle, $rowIndexOneBased, $columnIndexZeroBased)
|
||||
{
|
||||
// Apply row and extra styles
|
||||
$mergedCellAndRowStyle = $this->styleMerger->merge($cell->getStyle(), $rowStyle);
|
||||
$cell->setStyle($mergedCellAndRowStyle);
|
||||
$newCellStyle = $this->styleManager->applyExtraStylesIfNeeded($cell);
|
||||
if ($cell->getStyle() instanceof EmptyStyle) {
|
||||
$cell->setStyle($rowStyle);
|
||||
} else {
|
||||
$mergedCellAndRowStyle = $this->styleMerger->merge($cell->getStyle(), $rowStyle);
|
||||
$cell->setStyle($mergedCellAndRowStyle);
|
||||
}
|
||||
|
||||
$newCellStyle = $this->styleManager->applyExtraStylesIfNeeded($cell);
|
||||
$registeredStyle = $this->styleManager->registerStyle($newCellStyle);
|
||||
|
||||
return $this->getCellXML($rowIndexOneBased, $columnIndexZeroBased, $cell, $registeredStyle->getId());
|
||||
|
Loading…
x
Reference in New Issue
Block a user