Fix code style
This commit is contained in:
1 parent
740fcfb8c1
commit
b968513cb9
171 files changed
+517
-792
No files matched your search
@@ -4,17 +4,15 @@ namespace Box\Spout\Writer\XLSX\Creator;
|
||||
|
||||
use Box\Spout\Common\Helper\Escaper;
|
||||
use Box\Spout\Common\Helper\StringHelper;
|
||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||
use Box\Spout\Writer\Common\Creator\EntityFactory;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Writer\Common\Helper\ZipHelper;
|
||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||
use Box\Spout\Writer\XLSX\Helper\FileSystemHelper;
|
||||
|
||||
/**
|
||||
* Class HelperFactory
|
||||
* Factory for helpers needed by the XLSX Writer
|
||||
*
|
||||
* @package Box\Spout\Writer\XLSX\Creator
|
||||
*/
|
||||
class HelperFactory extends \Box\Spout\Common\Creator\HelperFactory
|
||||
{
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace Box\Spout\Writer\XLSX\Creator;
|
||||
|
||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||
use Box\Spout\Writer\Common\Creator\EntityFactory;
|
||||
use Box\Spout\Writer\Common\Creator\ManagerFactoryInterface;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||
use Box\Spout\Writer\Common\Manager\SheetManager;
|
||||
use Box\Spout\Writer\XLSX\Manager\SharedStringsManager;
|
||||
use Box\Spout\Writer\XLSX\Manager\Style\StyleManager;
|
||||
@@ -16,8 +16,6 @@ use Box\Spout\Writer\XLSX\Manager\WorksheetManager;
|
||||
/**
|
||||
* Class ManagerFactory
|
||||
* Factory for managers needed by the XLSX Writer
|
||||
*
|
||||
* @package Box\Spout\Writer\XLSX\Creator
|
||||
*/
|
||||
class ManagerFactory implements ManagerFactoryInterface
|
||||
{
|
||||
@@ -75,8 +73,7 @@ class ManagerFactory implements ManagerFactoryInterface
|
||||
OptionsManagerInterface $optionsManager,
|
||||
StyleManager $styleManager,
|
||||
SharedStringsManager $sharedStringsManager
|
||||
)
|
||||
{
|
||||
) {
|
||||
$stringsEscaper = $this->helperFactory->createStringsEscaper();
|
||||
$stringsHelper = $this->helperFactory->createStringHelper();
|
||||
|
||||
@@ -89,6 +86,7 @@ class ManagerFactory implements ManagerFactoryInterface
|
||||
public function createSheetManager()
|
||||
{
|
||||
$stringHelper = $this->helperFactory->createStringHelper();
|
||||
|
||||
return new SheetManager($stringHelper);
|
||||
}
|
||||
|
||||
@@ -99,6 +97,7 @@ class ManagerFactory implements ManagerFactoryInterface
|
||||
private function createStyleManager(OptionsManagerInterface $optionsManager)
|
||||
{
|
||||
$styleRegistry = $this->createStyleRegistry($optionsManager);
|
||||
|
||||
return new StyleManager($styleRegistry);
|
||||
}
|
||||
|
||||
@@ -109,6 +108,7 @@ class ManagerFactory implements ManagerFactoryInterface
|
||||
private function createStyleRegistry(OptionsManagerInterface $optionsManager)
|
||||
{
|
||||
$defaultRowStyle = $optionsManager->getOption(Options::DEFAULT_ROW_STYLE);
|
||||
|
||||
return new StyleRegistry($defaultRowStyle);
|
||||
}
|
||||
|
||||
@@ -119,6 +119,7 @@ class ManagerFactory implements ManagerFactoryInterface
|
||||
private function createSharedStringsManager($xlFolder)
|
||||
{
|
||||
$stringEscaper = $this->helperFactory->createStringsEscaper();
|
||||
|
||||
return new SharedStringsManager($xlFolder, $stringEscaper);
|
||||
}
|
||||
}
|
||||
@@ -9,29 +9,29 @@ class BorderHelper
|
||||
{
|
||||
public static $xlsxStyleMap = [
|
||||
Border::STYLE_SOLID => [
|
||||
Border::WIDTH_THIN => 'thin',
|
||||
Border::WIDTH_THIN => 'thin',
|
||||
Border::WIDTH_MEDIUM => 'medium',
|
||||
Border::WIDTH_THICK => 'thick'
|
||||
Border::WIDTH_THICK => 'thick',
|
||||
],
|
||||
Border::STYLE_DOTTED => [
|
||||
Border::WIDTH_THIN => 'dotted',
|
||||
Border::WIDTH_THIN => 'dotted',
|
||||
Border::WIDTH_MEDIUM => 'dotted',
|
||||
Border::WIDTH_THICK => 'dotted',
|
||||
Border::WIDTH_THICK => 'dotted',
|
||||
],
|
||||
Border::STYLE_DASHED => [
|
||||
Border::WIDTH_THIN => 'dashed',
|
||||
Border::WIDTH_THIN => 'dashed',
|
||||
Border::WIDTH_MEDIUM => 'mediumDashed',
|
||||
Border::WIDTH_THICK => 'mediumDashed',
|
||||
Border::WIDTH_THICK => 'mediumDashed',
|
||||
],
|
||||
Border::STYLE_DOUBLE => [
|
||||
Border::WIDTH_THIN => 'double',
|
||||
Border::WIDTH_THIN => 'double',
|
||||
Border::WIDTH_MEDIUM => 'double',
|
||||
Border::WIDTH_THICK => 'double',
|
||||
Border::WIDTH_THICK => 'double',
|
||||
],
|
||||
Border::STYLE_NONE => [
|
||||
Border::WIDTH_THIN => 'none',
|
||||
Border::WIDTH_THIN => 'none',
|
||||
Border::WIDTH_MEDIUM => 'none',
|
||||
Border::WIDTH_THICK => 'none',
|
||||
Border::WIDTH_THICK => 'none',
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
@@ -11,8 +11,6 @@ use Box\Spout\Writer\XLSX\Manager\Style\StyleManager;
|
||||
* Class FileSystemHelper
|
||||
* This class provides helper functions to help with the file system operations
|
||||
* like files/folders creation & deletion for XLSX files
|
||||
*
|
||||
* @package Box\Spout\Writer\XLSX\Helper
|
||||
*/
|
||||
class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper implements FileSystemWithRootFolderHelperInterface
|
||||
{
|
||||
@@ -94,8 +92,8 @@ class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper impleme
|
||||
/**
|
||||
* Creates all the folders needed to create a XLSX file, as well as the files that won't change.
|
||||
*
|
||||
* @return void
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to create at least one of the base folders
|
||||
* @return void
|
||||
*/
|
||||
public function createBaseFilesAndFolders()
|
||||
{
|
||||
@@ -109,20 +107,21 @@ class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper impleme
|
||||
/**
|
||||
* Creates the folder that will be used as root
|
||||
*
|
||||
* @return FileSystemHelper
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to create the folder
|
||||
* @return FileSystemHelper
|
||||
*/
|
||||
private function createRootFolder()
|
||||
{
|
||||
$this->rootFolder = $this->createFolder($this->baseFolderRealPath, uniqid('xlsx', true));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the "_rels" folder under the root folder as well as the ".rels" file in it
|
||||
*
|
||||
* @return FileSystemHelper
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or the ".rels" file
|
||||
* @return FileSystemHelper
|
||||
*/
|
||||
private function createRelsFolderAndFile()
|
||||
{
|
||||
@@ -136,12 +135,12 @@ class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper impleme
|
||||
/**
|
||||
* Creates the ".rels" file under the "_rels" folder (under root)
|
||||
*
|
||||
* @return FileSystemHelper
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to create the file
|
||||
* @return FileSystemHelper
|
||||
*/
|
||||
private function createRelsFile()
|
||||
{
|
||||
$relsFileContents = <<<EOD
|
||||
$relsFileContents = <<<'EOD'
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
||||
<Relationship Id="rIdWorkbook" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>
|
||||
@@ -158,8 +157,8 @@ EOD;
|
||||
/**
|
||||
* Creates the "docProps" folder under the root folder as well as the "app.xml" and "core.xml" files in it
|
||||
*
|
||||
* @return FileSystemHelper
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or one of the files
|
||||
* @return FileSystemHelper
|
||||
*/
|
||||
private function createDocPropsFolderAndFiles()
|
||||
{
|
||||
@@ -174,8 +173,8 @@ EOD;
|
||||
/**
|
||||
* Creates the "app.xml" file under the "docProps" folder
|
||||
*
|
||||
* @return FileSystemHelper
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to create the file
|
||||
* @return FileSystemHelper
|
||||
*/
|
||||
private function createAppXmlFile()
|
||||
{
|
||||
@@ -196,8 +195,8 @@ EOD;
|
||||
/**
|
||||
* Creates the "core.xml" file under the "docProps" folder
|
||||
*
|
||||
* @return FileSystemHelper
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to create the file
|
||||
* @return FileSystemHelper
|
||||
*/
|
||||
private function createCoreXmlFile()
|
||||
{
|
||||
@@ -219,8 +218,8 @@ EOD;
|
||||
/**
|
||||
* Creates the "xl" folder under the root folder as well as its subfolders
|
||||
*
|
||||
* @return FileSystemHelper
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to create at least one of the folders
|
||||
* @return FileSystemHelper
|
||||
*/
|
||||
private function createXlFolderAndSubFolders()
|
||||
{
|
||||
@@ -234,24 +233,26 @@ EOD;
|
||||
/**
|
||||
* Creates the "_rels" folder under the "xl" folder
|
||||
*
|
||||
* @return FileSystemHelper
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to create the folder
|
||||
* @return FileSystemHelper
|
||||
*/
|
||||
private function createXlRelsFolder()
|
||||
{
|
||||
$this->xlRelsFolder = $this->createFolder($this->xlFolder, self::RELS_FOLDER_NAME);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the "worksheets" folder under the "xl" folder
|
||||
*
|
||||
* @return FileSystemHelper
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to create the folder
|
||||
* @return FileSystemHelper
|
||||
*/
|
||||
private function createXlWorksheetsFolder()
|
||||
{
|
||||
$this->xlWorksheetsFolder = $this->createFolder($this->xlFolder, self::WORKSHEETS_FOLDER_NAME);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -263,7 +264,7 @@ EOD;
|
||||
*/
|
||||
public function createContentTypesFile($worksheets)
|
||||
{
|
||||
$contentTypesXmlFileContents = <<<EOD
|
||||
$contentTypesXmlFileContents = <<<'EOD'
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
|
||||
<Default ContentType="application/xml" Extension="xml"/>
|
||||
@@ -271,12 +272,12 @@ EOD;
|
||||
<Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml" PartName="/xl/workbook.xml"/>
|
||||
EOD;
|
||||
|
||||
/** @var Worksheet $worksheet */
|
||||
foreach ($worksheets as $worksheet) {
|
||||
$contentTypesXmlFileContents .= '<Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml" PartName="/xl/worksheets/sheet' . $worksheet->getId() . '.xml"/>';
|
||||
}
|
||||
/** @var Worksheet $worksheet */
|
||||
foreach ($worksheets as $worksheet) {
|
||||
$contentTypesXmlFileContents .= '<Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml" PartName="/xl/worksheets/sheet' . $worksheet->getId() . '.xml"/>';
|
||||
}
|
||||
|
||||
$contentTypesXmlFileContents .= <<<EOD
|
||||
$contentTypesXmlFileContents .= <<<'EOD'
|
||||
<Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml" PartName="/xl/styles.xml"/>
|
||||
<Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml" PartName="/xl/sharedStrings.xml"/>
|
||||
<Override ContentType="application/vnd.openxmlformats-package.core-properties+xml" PartName="/docProps/core.xml"/>
|
||||
@@ -297,7 +298,7 @@ EOD;
|
||||
*/
|
||||
public function createWorkbookFile($worksheets)
|
||||
{
|
||||
$workbookXmlFileContents = <<<EOD
|
||||
$workbookXmlFileContents = <<<'EOD'
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
|
||||
<sheets>
|
||||
@@ -310,7 +311,7 @@ EOD;
|
||||
$workbookXmlFileContents .= '<sheet name="' . $this->escaper->escape($worksheetName) . '" sheetId="' . $worksheetId . '" r:id="rIdSheet' . $worksheetId . '"/>';
|
||||
}
|
||||
|
||||
$workbookXmlFileContents .= <<<EOD
|
||||
$workbookXmlFileContents .= <<<'EOD'
|
||||
</sheets>
|
||||
</workbook>
|
||||
EOD;
|
||||
@@ -328,7 +329,7 @@ EOD;
|
||||
*/
|
||||
public function createWorkbookRelsFile($worksheets)
|
||||
{
|
||||
$workbookRelsXmlFileContents = <<<EOD
|
||||
$workbookRelsXmlFileContents = <<<'EOD'
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
||||
<Relationship Id="rIdStyles" Target="styles.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"/>
|
||||
|
||||
@@ -2,15 +2,13 @@
|
||||
|
||||
namespace Box\Spout\Writer\XLSX\Manager;
|
||||
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Common\Manager\OptionsManagerAbstract;
|
||||
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
|
||||
/**
|
||||
* Class OptionsManager
|
||||
* XLSX Writer options manager
|
||||
*
|
||||
* @package Box\Spout\Writer\XLSX\Manager
|
||||
*/
|
||||
class OptionsManager extends OptionsManagerAbstract
|
||||
{
|
||||
@@ -32,7 +30,7 @@ class OptionsManager extends OptionsManagerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getSupportedOptions()
|
||||
{
|
||||
@@ -45,7 +43,7 @@ class OptionsManager extends OptionsManagerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDefaultOptions()
|
||||
{
|
||||
|
||||
@@ -8,14 +8,12 @@ use Box\Spout\Common\Helper\Escaper;
|
||||
/**
|
||||
* Class SharedStringsManager
|
||||
* This class provides functions to write shared strings
|
||||
*
|
||||
* @package Box\Spout\Writer\XLSX\Manager
|
||||
*/
|
||||
class SharedStringsManager
|
||||
{
|
||||
const SHARED_STRINGS_FILE_NAME = 'sharedStrings.xml';
|
||||
|
||||
const SHARED_STRINGS_XML_FILE_FIRST_PART_HEADER = <<<EOD
|
||||
const SHARED_STRINGS_XML_FILE_FIRST_PART_HEADER = <<<'EOD'
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
|
||||
EOD;
|
||||
@@ -56,8 +54,8 @@ EOD;
|
||||
/**
|
||||
* Checks if the book has been created. Throws an exception if not created yet.
|
||||
*
|
||||
* @return void
|
||||
* @throws \Box\Spout\Common\Exception\IOException If the sheet data file cannot be opened for writing
|
||||
* @return void
|
||||
*/
|
||||
protected function throwIfSharedStringsFilePointerIsNotAvailable()
|
||||
{
|
||||
|
||||
@@ -9,8 +9,6 @@ use Box\Spout\Writer\XLSX\Helper\BorderHelper;
|
||||
/**
|
||||
* Class StyleManager
|
||||
* Manages styles to be applied to a cell
|
||||
*
|
||||
* @package Box\Spout\Writer\XLSX\Manager\Style
|
||||
*/
|
||||
class StyleManager extends \Box\Spout\Writer\Common\Manager\Style\StyleManager
|
||||
{
|
||||
@@ -38,7 +36,6 @@ class StyleManager extends \Box\Spout\Writer\Common\Manager\Style\StyleManager
|
||||
return ($hasStyleCustomFill || $hasStyleCustomBorders);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the content of the "styles.xml" file, given a list of styles.
|
||||
*
|
||||
@@ -46,7 +43,7 @@ class StyleManager extends \Box\Spout\Writer\Common\Manager\Style\StyleManager
|
||||
*/
|
||||
public function getStylesXMLFileContent()
|
||||
{
|
||||
$content = <<<EOD
|
||||
$content = <<<'EOD'
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
||||
EOD;
|
||||
@@ -58,7 +55,7 @@ EOD;
|
||||
$content .= $this->getCellXfsSectionContent();
|
||||
$content .= $this->getCellStylesSectionContent();
|
||||
|
||||
$content .= <<<EOD
|
||||
$content .= <<<'EOD'
|
||||
</styleSheet>
|
||||
EOD;
|
||||
|
||||
@@ -187,7 +184,7 @@ EOD;
|
||||
*/
|
||||
protected function getCellStyleXfsSectionContent()
|
||||
{
|
||||
return <<<EOD
|
||||
return <<<'EOD'
|
||||
<cellStyleXfs count="1">
|
||||
<xf borderId="0" fillId="0" fontId="0" numFmtId="0"/>
|
||||
</cellStyleXfs>
|
||||
@@ -239,7 +236,7 @@ EOD;
|
||||
*/
|
||||
protected function getCellStylesSectionContent()
|
||||
{
|
||||
return <<<EOD
|
||||
return <<<'EOD'
|
||||
<cellStyles count="1">
|
||||
<cellStyle builtinId="0" name="Normal" xfId="0"/>
|
||||
</cellStyles>
|
||||
|
||||
@@ -7,8 +7,6 @@ use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
/**
|
||||
* Class StyleRegistry
|
||||
* Registry for all used styles
|
||||
*
|
||||
* @package Box\Spout\Writer\XLSX\Manager\Style
|
||||
*/
|
||||
class StyleRegistry extends \Box\Spout\Writer\Common\Manager\Style\StyleRegistry
|
||||
{
|
||||
@@ -80,7 +78,6 @@ class StyleRegistry extends \Box\Spout\Writer\Common\Manager\Style\StyleRegistry
|
||||
$this->registeredFills[$backgroundColor] = $styleId;
|
||||
$this->styleIdToFillMappingTable[$styleId] = $this->fillIndex++;
|
||||
}
|
||||
|
||||
} else {
|
||||
// The fillId maps a style to a fill declaration
|
||||
// When there is no background color definition - we default to 0
|
||||
@@ -122,7 +119,6 @@ class StyleRegistry extends \Box\Spout\Writer\Common\Manager\Style\StyleRegistry
|
||||
$this->registeredBorders[$serializedBorder] = $styleId;
|
||||
$this->styleIdToBorderMappingTable[$styleId] = count($this->registeredBorders);
|
||||
}
|
||||
|
||||
} else {
|
||||
// If no border should be applied - the mapping is the default border: 0
|
||||
$this->styleIdToBorderMappingTable[$styleId] = 0;
|
||||
|
||||
@@ -10,8 +10,6 @@ use Box\Spout\Writer\XLSX\Manager\Style\StyleManager;
|
||||
/**
|
||||
* Class WorkbookManager
|
||||
* XLSX workbook manager, providing the interfaces to work with workbook.
|
||||
*
|
||||
* @package Box\Spout\Writer\XLSX\Manager
|
||||
*/
|
||||
class WorkbookManager extends WorkbookManagerAbstract
|
||||
{
|
||||
@@ -45,6 +43,7 @@ class WorkbookManager extends WorkbookManagerAbstract
|
||||
public function getWorksheetFilePath(Sheet $sheet)
|
||||
{
|
||||
$worksheetFilesFolder = $this->fileSystemHelper->getXlWorksheetsFolder();
|
||||
|
||||
return $worksheetFilesFolder . '/' . strtolower($sheet->getName()) . '.xml';
|
||||
}
|
||||
|
||||
@@ -75,4 +74,4 @@ class WorkbookManager extends WorkbookManagerAbstract
|
||||
->createStylesFile($this->styleManager)
|
||||
->zipRootFolderAndCopyToStream($finalFilePointer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,21 +5,19 @@ namespace Box\Spout\Writer\XLSX\Manager;
|
||||
use Box\Spout\Common\Exception\InvalidArgumentException;
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
use Box\Spout\Common\Helper\StringHelper;
|
||||
use Box\Spout\Writer\Common\Creator\EntityFactory;
|
||||
use Box\Spout\Writer\Common\Helper\CellHelper;
|
||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Writer\Common\Creator\EntityFactory;
|
||||
use Box\Spout\Writer\Common\Entity\Cell;
|
||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||
use Box\Spout\Writer\Common\Manager\WorksheetManagerInterface;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||
use Box\Spout\Writer\Common\Helper\CellHelper;
|
||||
use Box\Spout\Writer\Common\Manager\WorksheetManagerInterface;
|
||||
use Box\Spout\Writer\XLSX\Manager\Style\StyleManager;
|
||||
|
||||
/**
|
||||
* Class WorksheetManager
|
||||
* XLSX worksheet manager, providing the interfaces to work with XLSX worksheets.
|
||||
*
|
||||
* @package Box\Spout\Writer\XLSX\Manager
|
||||
*/
|
||||
class WorksheetManager implements WorksheetManagerInterface
|
||||
{
|
||||
@@ -31,7 +29,7 @@ class WorksheetManager implements WorksheetManagerInterface
|
||||
*/
|
||||
const MAX_CHARACTERS_PER_CELL = 32767;
|
||||
|
||||
const SHEET_XML_FILE_HEADER = <<<EOD
|
||||
const SHEET_XML_FILE_HEADER = <<<'EOD'
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
|
||||
EOD;
|
||||
@@ -70,8 +68,8 @@ EOD;
|
||||
SharedStringsManager $sharedStringsManager,
|
||||
\Box\Spout\Common\Helper\Escaper\XLSX $stringsEscaper,
|
||||
StringHelper $stringHelper,
|
||||
EntityFactory $entityFactory)
|
||||
{
|
||||
EntityFactory $entityFactory
|
||||
) {
|
||||
$this->shouldUseInlineStrings = $optionsManager->getOption(Options::SHOULD_USE_INLINE_STRINGS);
|
||||
$this->styleManager = $styleManager;
|
||||
$this->sharedStringsManager = $sharedStringsManager;
|
||||
@@ -88,13 +86,12 @@ EOD;
|
||||
return $this->sharedStringsManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepares the worksheet to accept data
|
||||
*
|
||||
* @param Worksheet $worksheet The worksheet to start
|
||||
* @return void
|
||||
* @throws \Box\Spout\Common\Exception\IOException If the sheet data file cannot be opened for writing
|
||||
* @return void
|
||||
*/
|
||||
public function startSheet(Worksheet $worksheet)
|
||||
{
|
||||
@@ -111,8 +108,8 @@ EOD;
|
||||
* Checks if the sheet has been sucessfully created. Throws an exception if not.
|
||||
*
|
||||
* @param bool|resource $sheetFilePointer Pointer to the sheet data file or FALSE if unable to open the file
|
||||
* @return void
|
||||
* @throws IOException If the sheet data file cannot be opened for writing
|
||||
* @return void
|
||||
*/
|
||||
private function throwIfSheetFilePointerIsNotAvailable($sheetFilePointer)
|
||||
{
|
||||
@@ -128,9 +125,9 @@ EOD;
|
||||
* @param array $dataRow Array containing data to be written. Cannot be empty.
|
||||
* Example $dataRow = ['data1', 1234, null, '', 'data5'];
|
||||
* @param Style $rowStyle Style to be applied to the row. NULL means use default style.
|
||||
* @return void
|
||||
* @throws IOException If the data cannot be written
|
||||
* @throws InvalidArgumentException If a cell value's type is not supported
|
||||
* @return void
|
||||
*/
|
||||
public function addRow(Worksheet $worksheet, $dataRow, $rowStyle)
|
||||
{
|
||||
@@ -162,9 +159,9 @@ EOD;
|
||||
* @param array $dataRow Array containing data to be written. Cannot be empty.
|
||||
* Example $dataRow = ['data1', 1234, null, '', 'data5'];
|
||||
* @param \Box\Spout\Writer\Common\Entity\Style\Style $style Style to be applied to the row. NULL means use default style.
|
||||
* @return void
|
||||
* @throws \Box\Spout\Common\Exception\IOException If the data cannot be written
|
||||
* @throws \Box\Spout\Common\Exception\InvalidArgumentException If a cell value's type is not supported
|
||||
* @return void
|
||||
*/
|
||||
private function addNonEmptyRow(Worksheet $worksheet, $dataRow, $style)
|
||||
{
|
||||
@@ -174,7 +171,7 @@ EOD;
|
||||
|
||||
$rowXML = '<row r="' . $rowIndex . '" spans="1:' . $numCells . '">';
|
||||
|
||||
foreach($dataRow as $cellValue) {
|
||||
foreach ($dataRow as $cellValue) {
|
||||
$rowXML .= $this->getCellXML($rowIndex, $cellNumber, $cellValue, $style->getId());
|
||||
$cellNumber++;
|
||||
}
|
||||
@@ -194,8 +191,8 @@ EOD;
|
||||
* @param int $cellNumber
|
||||
* @param mixed $cellValue
|
||||
* @param int $styleId
|
||||
* @return string
|
||||
* @throws InvalidArgumentException If the given value cannot be processed
|
||||
* @return string
|
||||
*/
|
||||
private function getCellXML($rowIndex, $cellNumber, $cellValue, $styleId)
|
||||
{
|
||||
@@ -203,7 +200,7 @@ EOD;
|
||||
$cellXML = '<c r="' . $columnIndex . $rowIndex . '"';
|
||||
$cellXML .= ' s="' . $styleId . '"';
|
||||
|
||||
/** @TODO Remove code duplication with ODS writer: https://github.com/box/spout/pull/383#discussion_r113292746 */
|
||||
/* @TODO Remove code duplication with ODS writer: https://github.com/box/spout/pull/383#discussion_r113292746 */
|
||||
if ($cellValue instanceof Cell) {
|
||||
$cell = $cellValue;
|
||||
} else {
|
||||
@@ -212,11 +209,11 @@ EOD;
|
||||
|
||||
if ($cell->isString()) {
|
||||
$cellXML .= $this->getCellXMLFragmentForNonEmptyString($cell->getValue());
|
||||
} else if ($cell->isBoolean()) {
|
||||
$cellXML .= ' t="b"><v>' . intval($cell->getValue()) . '</v></c>';
|
||||
} else if ($cell->isNumeric()) {
|
||||
} elseif ($cell->isBoolean()) {
|
||||
$cellXML .= ' t="b"><v>' . (int) ($cell->getValue()) . '</v></c>';
|
||||
} elseif ($cell->isNumeric()) {
|
||||
$cellXML .= '><v>' . $cell->getValue() . '</v></c>';
|
||||
} else if ($cell->isEmpty()) {
|
||||
} elseif ($cell->isEmpty()) {
|
||||
if ($this->styleManager->shouldApplyStyleOnEmptyCell($styleId)) {
|
||||
$cellXML .= '/>';
|
||||
} else {
|
||||
@@ -235,8 +232,8 @@ EOD;
|
||||
* Returns the XML fragment for a cell containing a non empty string
|
||||
*
|
||||
* @param string $cellValue The cell value
|
||||
* @return string The XML fragment representing the cell
|
||||
* @throws InvalidArgumentException If the string exceeds the maximum number of characters allowed per cell
|
||||
* @return string The XML fragment representing the cell
|
||||
*/
|
||||
private function getCellXMLFragmentForNonEmptyString($cellValue)
|
||||
{
|
||||
|
||||
@@ -8,8 +8,6 @@ use Box\Spout\Writer\WriterMultiSheetsAbstract;
|
||||
/**
|
||||
* Class Writer
|
||||
* This class provides base support to write data to XLSX files
|
||||
*
|
||||
* @package Box\Spout\Writer\XLSX
|
||||
*/
|
||||
class Writer extends WriterMultiSheetsAbstract
|
||||
{
|
||||
@@ -22,14 +20,15 @@ class Writer extends WriterMultiSheetsAbstract
|
||||
*
|
||||
* @api
|
||||
* @param string $tempFolder Temporary folder where the files to create the XLSX will be stored
|
||||
* @return Writer
|
||||
* @throws \Box\Spout\Writer\Exception\WriterAlreadyOpenedException If the writer was already opened
|
||||
* @return Writer
|
||||
*/
|
||||
public function setTempFolder($tempFolder)
|
||||
{
|
||||
$this->throwIfWriterAlreadyOpened('Writer must be configured before opening it.');
|
||||
|
||||
$this->optionsManager->setOption(Options::TEMP_FOLDER, $tempFolder);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -39,14 +38,15 @@ class Writer extends WriterMultiSheetsAbstract
|
||||
*
|
||||
* @api
|
||||
* @param bool $shouldUseInlineStrings Whether inline or shared strings should be used
|
||||
* @return Writer
|
||||
* @throws \Box\Spout\Writer\Exception\WriterAlreadyOpenedException If the writer was already opened
|
||||
* @return Writer
|
||||
*/
|
||||
public function setShouldUseInlineStrings($shouldUseInlineStrings)
|
||||
{
|
||||
$this->throwIfWriterAlreadyOpened('Writer must be configured before opening it.');
|
||||
|
||||
$this->optionsManager->setOption(Options::SHOULD_USE_INLINE_STRINGS, $shouldUseInlineStrings);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user