Begin optimize xlsx write
This commit is contained in:
parent
ed9322e309
commit
9a4f229774
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);
|
$serializedStyle = $this->serialize($style);
|
||||||
|
|
||||||
if (!$this->hasStyleAlreadyBeenRegistered($style)) {
|
if (!$this->hasSerializedStyleAlreadyBeenRegistered($serializedStyle)) {
|
||||||
$nextStyleId = \count($this->serializedStyleToStyleIdMappingTable);
|
$nextStyleId = \count($this->serializedStyleToStyleIdMappingTable);
|
||||||
$style->setId($nextStyleId);
|
$style->setId($nextStyleId);
|
||||||
|
|
||||||
@ -57,6 +57,17 @@ class StyleRegistry
|
|||||||
{
|
{
|
||||||
$serializedStyle = $this->serialize($style);
|
$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...
|
// Using isset here because it is way faster than array_key_exists...
|
||||||
return isset($this->serializedStyleToStyleIdMappingTable[$serializedStyle]);
|
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\Cell;
|
||||||
use Box\Spout\Common\Entity\Row;
|
use Box\Spout\Common\Entity\Row;
|
||||||
|
use Box\Spout\Common\Entity\Style\EmptyStyle;
|
||||||
use Box\Spout\Common\Entity\Style\Style;
|
use Box\Spout\Common\Entity\Style\Style;
|
||||||
use Box\Spout\Common\Exception\InvalidArgumentException;
|
use Box\Spout\Common\Exception\InvalidArgumentException;
|
||||||
use Box\Spout\Common\Exception\IOException;
|
use Box\Spout\Common\Exception\IOException;
|
||||||
@ -157,9 +158,13 @@ class WorksheetManager implements WorksheetManagerInterface
|
|||||||
*/
|
*/
|
||||||
private function applyStyleAndGetCellXML(Cell $cell, Style $rowStyle, $currentCellIndex, $nextCellIndex)
|
private function applyStyleAndGetCellXML(Cell $cell, Style $rowStyle, $currentCellIndex, $nextCellIndex)
|
||||||
{
|
{
|
||||||
// Apply row and extra styles
|
if ($cell->getStyle() instanceof EmptyStyle) {
|
||||||
$mergedCellAndRowStyle = $this->styleMerger->merge($cell->getStyle(), $rowStyle);
|
$cell->setStyle($rowStyle);
|
||||||
$cell->setStyle($mergedCellAndRowStyle);
|
} else {
|
||||||
|
$mergedCellAndRowStyle = $this->styleMerger->merge($cell->getStyle(), $rowStyle);
|
||||||
|
$cell->setStyle($mergedCellAndRowStyle);
|
||||||
|
}
|
||||||
|
|
||||||
$newCellStyle = $this->styleManager->applyExtraStylesIfNeeded($cell);
|
$newCellStyle = $this->styleManager->applyExtraStylesIfNeeded($cell);
|
||||||
|
|
||||||
$registeredStyle = $this->styleManager->registerStyle($newCellStyle);
|
$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\Cell;
|
||||||
use Box\Spout\Common\Entity\Row;
|
use Box\Spout\Common\Entity\Row;
|
||||||
|
use Box\Spout\Common\Entity\Style\EmptyStyle;
|
||||||
use Box\Spout\Common\Entity\Style\Style;
|
use Box\Spout\Common\Entity\Style\Style;
|
||||||
use Box\Spout\Common\Exception\InvalidArgumentException;
|
use Box\Spout\Common\Exception\InvalidArgumentException;
|
||||||
use Box\Spout\Common\Exception\IOException;
|
use Box\Spout\Common\Exception\IOException;
|
||||||
@ -185,11 +186,14 @@ EOD;
|
|||||||
*/
|
*/
|
||||||
private function applyStyleAndGetCellXML(Cell $cell, Style $rowStyle, $rowIndexOneBased, $columnIndexZeroBased)
|
private function applyStyleAndGetCellXML(Cell $cell, Style $rowStyle, $rowIndexOneBased, $columnIndexZeroBased)
|
||||||
{
|
{
|
||||||
// Apply row and extra styles
|
if ($cell->getStyle() instanceof EmptyStyle) {
|
||||||
$mergedCellAndRowStyle = $this->styleMerger->merge($cell->getStyle(), $rowStyle);
|
$cell->setStyle($rowStyle);
|
||||||
$cell->setStyle($mergedCellAndRowStyle);
|
} else {
|
||||||
$newCellStyle = $this->styleManager->applyExtraStylesIfNeeded($cell);
|
$mergedCellAndRowStyle = $this->styleMerger->merge($cell->getStyle(), $rowStyle);
|
||||||
|
$cell->setStyle($mergedCellAndRowStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
$newCellStyle = $this->styleManager->applyExtraStylesIfNeeded($cell);
|
||||||
$registeredStyle = $this->styleManager->registerStyle($newCellStyle);
|
$registeredStyle = $this->styleManager->registerStyle($newCellStyle);
|
||||||
|
|
||||||
return $this->getCellXML($rowIndexOneBased, $columnIndexZeroBased, $cell, $registeredStyle->getId());
|
return $this->getCellXML($rowIndexOneBased, $columnIndexZeroBased, $cell, $registeredStyle->getId());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user