Add support for default cell sizes for ODS files
This commit is contained in:
1 parent
6db9871722
commit
26ad59033c
3 files changed
+104
-11
No files matched your search
@@ -4,6 +4,7 @@ namespace Box\Spout\Writer\ODS\Manager\Style;
|
||||
|
||||
use Box\Spout\Common\Entity\Style\BorderPart;
|
||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||
use Box\Spout\Writer\Common\Manager\ManagesCellSize;
|
||||
use Box\Spout\Writer\ODS\Helper\BorderHelper;
|
||||
|
||||
/**
|
||||
@@ -12,6 +13,8 @@ use Box\Spout\Writer\ODS\Helper\BorderHelper;
|
||||
*/
|
||||
class StyleManager extends \Box\Spout\Writer\Common\Manager\Style\StyleManager
|
||||
{
|
||||
use ManagesCellSize;
|
||||
|
||||
/** @var StyleRegistry */
|
||||
protected $styleRegistry;
|
||||
|
||||
@@ -161,12 +164,16 @@ EOD;
|
||||
$content .= $this->getStyleSectionContent($style);
|
||||
}
|
||||
|
||||
$content .= <<<'EOD'
|
||||
$useOptimalRowHeight = empty($this->defaultRowHeight) ? 'true' : 'false';
|
||||
$defaultRowHeight = empty($this->defaultRowHeight) ? '15pt' : "{$this->defaultRowHeight}pt";
|
||||
$defaultColumnWidth = empty($this->defaultColumnWidth) ? '' : "style:column-width=\"{$this->defaultColumnWidth}pt\"";
|
||||
|
||||
$content .= <<<EOD
|
||||
<style:style style:family="table-column" style:name="co1">
|
||||
<style:table-column-properties fo:break-before="auto"/>
|
||||
<style:table-column-properties fo:break-before="auto" {$defaultColumnWidth}/>
|
||||
</style:style>
|
||||
<style:style style:family="table-row" style:name="ro1">
|
||||
<style:table-row-properties fo:break-before="auto" style:row-height="15pt" style:use-optimal-row-height="true"/>
|
||||
<style:table-row-properties fo:break-before="auto" style:row-height="{$defaultRowHeight}" style:use-optimal-row-height="{$useOptimalRowHeight}"/>
|
||||
</style:style>
|
||||
EOD;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ use Box\Spout\Common\Exception\InvalidArgumentException;
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
use Box\Spout\Common\Helper\Escaper\ODS as ODSEscaper;
|
||||
use Box\Spout\Common\Helper\StringHelper;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
|
||||
use Box\Spout\Writer\Common\Manager\WorksheetManagerInterface;
|
||||
@@ -39,17 +40,25 @@ class WorksheetManager implements WorksheetManagerInterface
|
||||
* @param StyleMerger $styleMerger
|
||||
* @param ODSEscaper $stringsEscaper
|
||||
* @param StringHelper $stringHelper
|
||||
* @param OptionsManager|null $optionsManager
|
||||
*/
|
||||
public function __construct(
|
||||
StyleManager $styleManager,
|
||||
StyleMerger $styleMerger,
|
||||
ODSEscaper $stringsEscaper,
|
||||
StringHelper $stringHelper
|
||||
StringHelper $stringHelper,
|
||||
$optionsManager = null
|
||||
) {
|
||||
$this->styleManager = $styleManager;
|
||||
$this->styleMerger = $styleMerger;
|
||||
$this->stringsEscaper = $stringsEscaper;
|
||||
$this->stringHelper = $stringHelper;
|
||||
|
||||
if ($optionsManager) {
|
||||
$this->setDefaultColumnWidth($optionsManager->getOption(Options::DEFAULT_COLUMN_WIDTH));
|
||||
$this->setDefaultRowHeight($optionsManager->getOption(Options::DEFAULT_ROW_HEIGHT));
|
||||
$this->columnWidths = $optionsManager->getOption(Options::COLUMN_WIDTHS) ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,4 +238,39 @@ class WorksheetManager implements WorksheetManagerInterface
|
||||
|
||||
fclose($worksheetFilePointer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float|null $width
|
||||
*/
|
||||
public function setDefaultColumnWidth($width)
|
||||
{
|
||||
$this->styleManager->setDefaultColumnWidth($width);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float|null $height
|
||||
*/
|
||||
public function setDefaultRowHeight($height)
|
||||
{
|
||||
$this->styleManager->setDefaultRowHeight($height);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $width
|
||||
* @param array $columns One or more columns with this width
|
||||
*/
|
||||
public function setColumnWidth(float $width, ...$columns)
|
||||
{
|
||||
$this->styleManager->setColumnWidth($width, ...$columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $width The width to set
|
||||
* @param int $start First column index of the range
|
||||
* @param int $end Last column index of the range
|
||||
*/
|
||||
public function setColumnWidthForRange(float $width, int $start, int $end)
|
||||
{
|
||||
$this->styleManager->setColumnWidthForRange($width, $start, $end);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user