Fix code style
This commit is contained in:
1 parent
740fcfb8c1
commit
b968513cb9
171 files changed
+517
-792
No files matched your search
@@ -2,19 +2,17 @@
|
||||
|
||||
namespace Box\Spout\Writer\CSV\Manager;
|
||||
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Common\Manager\OptionsManagerAbstract;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
|
||||
/**
|
||||
* Class OptionsManager
|
||||
* CSV Writer options manager
|
||||
*
|
||||
* @package Box\Spout\Writer\CSV\Manager
|
||||
*/
|
||||
class OptionsManager extends OptionsManagerAbstract
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getSupportedOptions()
|
||||
{
|
||||
@@ -26,7 +24,7 @@ class OptionsManager extends OptionsManagerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDefaultOptions()
|
||||
{
|
||||
|
||||
@@ -2,16 +2,14 @@
|
||||
|
||||
namespace Box\Spout\Writer\CSV;
|
||||
|
||||
use Box\Spout\Writer\WriterAbstract;
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
use Box\Spout\Common\Helper\EncodingHelper;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Writer\WriterAbstract;
|
||||
|
||||
/**
|
||||
* Class Writer
|
||||
* This class provides support to write data to CSV files
|
||||
*
|
||||
* @package Box\Spout\Writer\CSV
|
||||
*/
|
||||
class Writer extends WriterAbstract
|
||||
{
|
||||
@@ -34,6 +32,7 @@ class Writer extends WriterAbstract
|
||||
public function setFieldDelimiter($fieldDelimiter)
|
||||
{
|
||||
$this->optionsManager->setOption(Options::FIELD_DELIMITER, $fieldDelimiter);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -47,6 +46,7 @@ class Writer extends WriterAbstract
|
||||
public function setFieldEnclosure($fieldEnclosure)
|
||||
{
|
||||
$this->optionsManager->setOption(Options::FIELD_ENCLOSURE, $fieldEnclosure);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ class Writer extends WriterAbstract
|
||||
public function setShouldAddBOM($shouldAddBOM)
|
||||
{
|
||||
$this->optionsManager->setOption(Options::SHOULD_ADD_BOM, (bool) $shouldAddBOM);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -82,8 +83,8 @@ class Writer extends WriterAbstract
|
||||
* @param array $dataRow Array containing data to be written.
|
||||
* Example $dataRow = ['data1', 1234, null, '', 'data5'];
|
||||
* @param \Box\Spout\Writer\Common\Entity\Style\Style $style Ignored here since CSV does not support styling.
|
||||
* @return void
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to write data
|
||||
* @return void
|
||||
*/
|
||||
protected function addRowToWriter(array $dataRow, $style)
|
||||
{
|
||||
|
||||
@@ -11,8 +11,6 @@ use Box\Spout\Writer\Common\Manager\SheetManager;
|
||||
/**
|
||||
* Class EntityFactory
|
||||
* Factory to create entities
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Creator
|
||||
*/
|
||||
class EntityFactory
|
||||
{
|
||||
|
||||
@@ -8,8 +8,6 @@ use Box\Spout\Writer\Common\Manager\WorkbookManagerInterface;
|
||||
|
||||
/**
|
||||
* Interface ManagerFactoryInterface
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Creator
|
||||
*/
|
||||
interface ManagerFactoryInterface
|
||||
{
|
||||
|
||||
@@ -8,8 +8,6 @@ use Box\Spout\Writer\Common\Entity\Style\Color;
|
||||
|
||||
/**
|
||||
* Class BorderBuilder
|
||||
*
|
||||
* @package \Box\Spout\Writer\Common\Creator\Style
|
||||
*/
|
||||
class BorderBuilder
|
||||
{
|
||||
@@ -32,6 +30,7 @@ class BorderBuilder
|
||||
public function setBorderTop($color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID)
|
||||
{
|
||||
$this->border->addPart(new BorderPart(Border::TOP, $color, $width, $style));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -44,6 +43,7 @@ class BorderBuilder
|
||||
public function setBorderRight($color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID)
|
||||
{
|
||||
$this->border->addPart(new BorderPart(Border::RIGHT, $color, $width, $style));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ class BorderBuilder
|
||||
public function setBorderBottom($color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID)
|
||||
{
|
||||
$this->border->addPart(new BorderPart(Border::BOTTOM, $color, $width, $style));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -68,6 +69,7 @@ class BorderBuilder
|
||||
public function setBorderLeft($color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID)
|
||||
{
|
||||
$this->border->addPart(new BorderPart(Border::LEFT, $color, $width, $style));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@ use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
/**
|
||||
* Class StyleBuilder
|
||||
* Builder to create new styles
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Creator\Style
|
||||
*/
|
||||
class StyleBuilder
|
||||
{
|
||||
@@ -33,6 +31,7 @@ class StyleBuilder
|
||||
public function setFontBold()
|
||||
{
|
||||
$this->style->setFontBold();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -45,6 +44,7 @@ class StyleBuilder
|
||||
public function setFontItalic()
|
||||
{
|
||||
$this->style->setFontItalic();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ class StyleBuilder
|
||||
public function setFontUnderline()
|
||||
{
|
||||
$this->style->setFontUnderline();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -69,6 +70,7 @@ class StyleBuilder
|
||||
public function setFontStrikethrough()
|
||||
{
|
||||
$this->style->setFontStrikethrough();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -82,6 +84,7 @@ class StyleBuilder
|
||||
public function setFontSize($fontSize)
|
||||
{
|
||||
$this->style->setFontSize($fontSize);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -95,6 +98,7 @@ class StyleBuilder
|
||||
public function setFontColor($fontColor)
|
||||
{
|
||||
$this->style->setFontColor($fontColor);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -108,6 +112,7 @@ class StyleBuilder
|
||||
public function setFontName($fontName)
|
||||
{
|
||||
$this->style->setFontName($fontName);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -121,6 +126,7 @@ class StyleBuilder
|
||||
public function setShouldWrapText($shouldWrap = true)
|
||||
{
|
||||
$this->style->setShouldWrapText($shouldWrap);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -133,6 +139,7 @@ class StyleBuilder
|
||||
public function setBorder(Border $border)
|
||||
{
|
||||
$this->style->setBorder($border);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -146,6 +153,7 @@ class StyleBuilder
|
||||
public function setBackgroundColor($color)
|
||||
{
|
||||
$this->style->setBackgroundColor($color);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@ use Box\Spout\Writer\Common\Helper\CellHelper;
|
||||
|
||||
/**
|
||||
* Class Cell
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Entity
|
||||
*/
|
||||
class Cell
|
||||
{
|
||||
@@ -46,13 +44,13 @@ class Cell
|
||||
* The value of this cell
|
||||
* @var mixed|null
|
||||
*/
|
||||
protected $value = null;
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* The cell type
|
||||
* @var int|null
|
||||
*/
|
||||
protected $type = null;
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* Cell constructor.
|
||||
@@ -165,6 +163,6 @@ class Cell
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return (string)$this->value;
|
||||
return (string) $this->value;
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,6 @@ namespace Box\Spout\Writer\Common\Entity;
|
||||
/**
|
||||
* Class Options
|
||||
* Writers' options holder
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Entity
|
||||
*/
|
||||
abstract class Options
|
||||
{
|
||||
|
||||
@@ -7,8 +7,6 @@ use Box\Spout\Writer\Common\Manager\SheetManager;
|
||||
/**
|
||||
* Class Sheet
|
||||
* External representation of a worksheet
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Entity
|
||||
*/
|
||||
class Sheet
|
||||
{
|
||||
@@ -77,8 +75,8 @@ class Sheet
|
||||
*
|
||||
* @api
|
||||
* @param string $name Name of the sheet
|
||||
* @return Sheet
|
||||
* @throws \Box\Spout\Writer\Exception\InvalidSheetNameException If the sheet's name is invalid.
|
||||
* @return Sheet
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
|
||||
@@ -4,8 +4,6 @@ namespace Box\Spout\Writer\Common\Entity\Style;
|
||||
|
||||
/**
|
||||
* Class Border
|
||||
*
|
||||
* @package \Box\Spout\Writer\Common\Entity\Style
|
||||
*/
|
||||
class Border
|
||||
{
|
||||
@@ -37,7 +35,7 @@ class Border
|
||||
|
||||
/**
|
||||
* @param string $name The name of the border part
|
||||
* @return null|BorderPart
|
||||
* @return BorderPart|null
|
||||
*/
|
||||
public function getPart($name)
|
||||
{
|
||||
@@ -81,6 +79,7 @@ class Border
|
||||
public function addPart(BorderPart $borderPart)
|
||||
{
|
||||
$this->parts[$borderPart->getName()] = $borderPart;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,6 @@ use Box\Spout\Writer\Exception\Border\InvalidWidthException;
|
||||
|
||||
/**
|
||||
* Class BorderPart
|
||||
*
|
||||
* @package \Box\Spout\Writer\Common\Entity\Style
|
||||
*/
|
||||
class BorderPart
|
||||
{
|
||||
@@ -41,7 +39,7 @@ class BorderPart
|
||||
'solid',
|
||||
'dashed',
|
||||
'dotted',
|
||||
'double'
|
||||
'double',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,8 +7,6 @@ use Box\Spout\Writer\Exception\InvalidColorException;
|
||||
/**
|
||||
* Class Color
|
||||
* This class provides constants and functions to work with colors
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Entity\Style
|
||||
*/
|
||||
class Color
|
||||
{
|
||||
@@ -52,8 +50,8 @@ class Color
|
||||
* Throws an exception is the color component value is outside of bounds (0 - 255)
|
||||
*
|
||||
* @param int $colorComponent
|
||||
* @return void
|
||||
* @throws \Box\Spout\Writer\Exception\InvalidColorException
|
||||
* @return void
|
||||
*/
|
||||
protected static function throwIfInvalidColorComponentValue($colorComponent)
|
||||
{
|
||||
|
||||
@@ -5,8 +5,6 @@ namespace Box\Spout\Writer\Common\Entity\Style;
|
||||
/**
|
||||
* Class Style
|
||||
* Represents a style to be applied to a cell
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Entity\Style
|
||||
*/
|
||||
class Style
|
||||
{
|
||||
@@ -16,7 +14,7 @@ class Style
|
||||
const DEFAULT_FONT_NAME = 'Arial';
|
||||
|
||||
/** @var int|null Style ID */
|
||||
private $id = null;
|
||||
private $id;
|
||||
|
||||
/** @var bool Whether the font should be bold */
|
||||
private $fontBold = false;
|
||||
@@ -62,18 +60,17 @@ class Style
|
||||
private $hasSetWrapText = false;
|
||||
|
||||
/** @var Border */
|
||||
private $border = null;
|
||||
private $border;
|
||||
|
||||
/** @var bool Whether border properties should be applied */
|
||||
private $shouldApplyBorder = false;
|
||||
|
||||
/** @var string Background color */
|
||||
private $backgroundColor = null;
|
||||
private $backgroundColor;
|
||||
|
||||
/** @var bool */
|
||||
private $hasSetBackgroundColor = false;
|
||||
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
@@ -89,6 +86,7 @@ class Style
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -108,6 +106,7 @@ class Style
|
||||
{
|
||||
$this->shouldApplyBorder = true;
|
||||
$this->border = $border;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -135,6 +134,7 @@ class Style
|
||||
$this->fontBold = true;
|
||||
$this->hasSetFontBold = true;
|
||||
$this->shouldApplyFont = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -162,6 +162,7 @@ class Style
|
||||
$this->fontItalic = true;
|
||||
$this->hasSetFontItalic = true;
|
||||
$this->shouldApplyFont = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -189,6 +190,7 @@ class Style
|
||||
$this->fontUnderline = true;
|
||||
$this->hasSetFontUnderline = true;
|
||||
$this->shouldApplyFont = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -216,6 +218,7 @@ class Style
|
||||
$this->fontStrikethrough = true;
|
||||
$this->hasSetFontStrikethrough = true;
|
||||
$this->shouldApplyFont = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -244,6 +247,7 @@ class Style
|
||||
$this->fontSize = $fontSize;
|
||||
$this->hasSetFontSize = true;
|
||||
$this->shouldApplyFont = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -274,6 +278,7 @@ class Style
|
||||
$this->fontColor = $fontColor;
|
||||
$this->hasSetFontColor = true;
|
||||
$this->shouldApplyFont = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -302,6 +307,7 @@ class Style
|
||||
$this->fontName = $fontName;
|
||||
$this->hasSetFontName = true;
|
||||
$this->shouldApplyFont = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -329,6 +335,7 @@ class Style
|
||||
{
|
||||
$this->shouldWrapText = $shouldWrap;
|
||||
$this->hasSetWrapText = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -357,6 +364,7 @@ class Style
|
||||
{
|
||||
$this->hasSetBackgroundColor = true;
|
||||
$this->backgroundColor = $color;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -369,7 +377,6 @@ class Style
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool Whether the background color should be applied
|
||||
*/
|
||||
public function shouldApplyBackgroundColor()
|
||||
|
||||
@@ -5,8 +5,6 @@ namespace Box\Spout\Writer\Common\Entity;
|
||||
/**
|
||||
* Class Workbook
|
||||
* Entity describing a workbook
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Entity
|
||||
*/
|
||||
class Workbook
|
||||
{
|
||||
@@ -47,4 +45,4 @@ class Workbook
|
||||
{
|
||||
return $this->internalId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,15 +5,13 @@ namespace Box\Spout\Writer\Common\Entity;
|
||||
/**
|
||||
* Class Worksheet
|
||||
* Entity describing a Worksheet
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Entity
|
||||
*/
|
||||
class Worksheet
|
||||
{
|
||||
/** @var string Path to the XML file that will contain the sheet data */
|
||||
private $filePath;
|
||||
|
||||
/** @var Resource Pointer to the sheet data file (e.g. xl/worksheets/sheet1.xml) */
|
||||
/** @var resource Pointer to the sheet data file (e.g. xl/worksheets/sheet1.xml) */
|
||||
private $filePointer;
|
||||
|
||||
/** @var Sheet The "external" sheet */
|
||||
@@ -49,7 +47,7 @@ class Worksheet
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Resource
|
||||
* @return resource
|
||||
*/
|
||||
public function getFilePointer()
|
||||
{
|
||||
@@ -57,7 +55,7 @@ class Worksheet
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Resource $filePointer
|
||||
* @param resource $filePointer
|
||||
*/
|
||||
public function setFilePointer($filePointer)
|
||||
{
|
||||
@@ -112,4 +110,4 @@ class Worksheet
|
||||
// sheet index is zero-based, while ID is 1-based
|
||||
return $this->externalSheet->getIndex() + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,6 @@ namespace Box\Spout\Writer\Common\Helper;
|
||||
/**
|
||||
* Class CellHelper
|
||||
* This class provides helper functions when working with cells
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Helper
|
||||
*/
|
||||
class CellHelper
|
||||
{
|
||||
@@ -36,8 +34,7 @@ class CellHelper
|
||||
$cellIndex = chr($capitalAAsciiValue + $modulus) . $cellIndex;
|
||||
|
||||
// substracting 1 because it's zero-based
|
||||
$columnIndex = intval($columnIndex / 26) - 1;
|
||||
|
||||
$columnIndex = (int) ($columnIndex / 26) - 1;
|
||||
} while ($columnIndex >= 0);
|
||||
|
||||
self::$columnIndexToCellIndexCache[$originalColumnIndex] = $cellIndex;
|
||||
@@ -74,6 +71,7 @@ class CellHelper
|
||||
public static function isNumeric($value)
|
||||
{
|
||||
$valueType = gettype($value);
|
||||
|
||||
return ($valueType === 'integer' || $valueType === 'double');
|
||||
}
|
||||
|
||||
|
||||
@@ -2,22 +2,20 @@
|
||||
|
||||
namespace Box\Spout\Writer\Common\Helper;
|
||||
|
||||
use \Box\Spout\Common\Helper\FileSystemHelperInterface;
|
||||
use Box\Spout\Common\Helper\FileSystemHelperInterface;
|
||||
|
||||
/**
|
||||
* Class FileSystemHelperInterface
|
||||
* This interface describes helper functions to help with the file system operations
|
||||
* like files/folders creation & deletion
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Helper
|
||||
*/
|
||||
interface FileSystemWithRootFolderHelperInterface extends FileSystemHelperInterface
|
||||
{
|
||||
/**
|
||||
* Creates all the folders needed to create a spreadsheet, 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();
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@ use Box\Spout\Writer\Common\Creator\EntityFactory;
|
||||
/**
|
||||
* Class ZipHelper
|
||||
* This class provides helper functions to create zip files
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Helper
|
||||
*/
|
||||
class ZipHelper
|
||||
{
|
||||
@@ -40,7 +38,7 @@ class ZipHelper
|
||||
$zip = $this->entityFactory->createZipArchive();
|
||||
$zipFilePath = $tmpFolderPath . self::ZIP_EXTENSION;
|
||||
|
||||
$zip->open($zipFilePath, \ZipArchive::CREATE|\ZipArchive::OVERWRITE);
|
||||
$zip->open($zipFilePath, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
|
||||
|
||||
return $zip;
|
||||
}
|
||||
@@ -184,6 +182,7 @@ class ZipHelper
|
||||
protected function getNormalizedRealPath($path)
|
||||
{
|
||||
$realPath = realpath($path);
|
||||
|
||||
return str_replace(DIRECTORY_SEPARATOR, '/', $realPath);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,6 @@ use Box\Spout\Writer\Exception\InvalidSheetNameException;
|
||||
/**
|
||||
* Class SheetManager
|
||||
* Sheet manager
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Manager
|
||||
*/
|
||||
class SheetManager
|
||||
{
|
||||
@@ -42,8 +40,8 @@ class SheetManager
|
||||
*
|
||||
* @param string $name
|
||||
* @param Sheet $sheet The sheet whose future name is checked
|
||||
* @return void
|
||||
* @throws \Box\Spout\Writer\Exception\InvalidSheetNameException If the sheet's name is invalid.
|
||||
* @return void
|
||||
*/
|
||||
public function throwIfNameIsInvalid($name, Sheet $sheet)
|
||||
{
|
||||
|
||||
@@ -7,8 +7,6 @@ use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
/**
|
||||
* Class StyleManager
|
||||
* Manages styles to be applied to a cell
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Manager\Style
|
||||
*/
|
||||
class StyleManager implements StyleManagerInterface
|
||||
{
|
||||
@@ -57,6 +55,7 @@ class StyleManager implements StyleManagerInterface
|
||||
public function applyExtraStylesIfNeeded($style, $dataRow)
|
||||
{
|
||||
$updatedStyle = $this->applyWrapTextIfCellContainsNewLine($style, $dataRow);
|
||||
|
||||
return $updatedStyle;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@ use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
|
||||
/**
|
||||
* Interface StyleHManagernterface
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Manager\Style
|
||||
*/
|
||||
interface StyleManagerInterface
|
||||
{
|
||||
|
||||
@@ -2,15 +2,11 @@
|
||||
|
||||
namespace Box\Spout\Writer\Common\Manager\Style;
|
||||
|
||||
use Box\Spout\Writer\Common\Entity\Style\Color;
|
||||
use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
use Box\Spout\Writer\XLSX\Helper\BorderHelper;
|
||||
|
||||
/**
|
||||
* Class StyleMerger
|
||||
* Takes care of merging styles together
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Manager\Style
|
||||
*/
|
||||
class StyleMerger
|
||||
{
|
||||
|
||||
@@ -7,8 +7,6 @@ use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
/**
|
||||
* Class StyleRegistry
|
||||
* Registry for all used styles
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Manager\Style
|
||||
*/
|
||||
class StyleRegistry
|
||||
{
|
||||
@@ -72,6 +70,7 @@ class StyleRegistry
|
||||
protected function getStyleFromSerializedStyle($serializedStyle)
|
||||
{
|
||||
$styleId = $this->serializedStyleToStyleIdMappingTable[$serializedStyle];
|
||||
|
||||
return $this->styleIdToStyleMappingTable[$styleId];
|
||||
}
|
||||
|
||||
|
||||
@@ -4,23 +4,21 @@ namespace Box\Spout\Writer\Common\Manager;
|
||||
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
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\Helper\FileSystemWithRootFolderHelperInterface;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Writer\Common\Manager\Style\StyleManagerInterface;
|
||||
use Box\Spout\Writer\Common\Entity\Sheet;
|
||||
use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
use Box\Spout\Writer\Common\Entity\Workbook;
|
||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||
use Box\Spout\Writer\Common\Helper\FileSystemWithRootFolderHelperInterface;
|
||||
use Box\Spout\Writer\Common\Manager\Style\StyleManagerInterface;
|
||||
use Box\Spout\Writer\Exception\SheetNotFoundException;
|
||||
use Box\Spout\Writer\Exception\WriterException;
|
||||
use Box\Spout\Writer\Common\Creator\EntityFactory;
|
||||
use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
|
||||
/**
|
||||
* Class WorkbookManagerAbstract
|
||||
* Abstract workbook manager, providing the generic interfaces to work with workbook.
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Manager
|
||||
*/
|
||||
abstract class WorkbookManagerAbstract implements WorkbookManagerInterface
|
||||
{
|
||||
@@ -48,7 +46,6 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface
|
||||
/** @var Worksheet The worksheet where data will be written to */
|
||||
protected $currentWorksheet;
|
||||
|
||||
|
||||
/**
|
||||
* @param Workbook $workbook
|
||||
* @param OptionsManagerInterface $optionsManager
|
||||
@@ -65,8 +62,8 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface
|
||||
StyleManagerInterface $styleManager,
|
||||
FileSystemWithRootFolderHelperInterface $fileSystemHelper,
|
||||
EntityFactory $entityFactory,
|
||||
ManagerFactoryInterface $managerFactory)
|
||||
{
|
||||
ManagerFactoryInterface $managerFactory
|
||||
) {
|
||||
$this->workbook = $workbook;
|
||||
$this->optionManager = $optionsManager;
|
||||
$this->worksheetManager = $worksheetManager;
|
||||
@@ -99,8 +96,8 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface
|
||||
* Creates a new sheet in the workbook and make it the current sheet.
|
||||
* The writing will resume where it stopped (i.e. data won't be truncated).
|
||||
*
|
||||
* @return Worksheet The created sheet
|
||||
* @throws IOException If unable to open the sheet for writing
|
||||
* @return Worksheet The created sheet
|
||||
*/
|
||||
public function addNewSheetAndMakeItCurrent()
|
||||
{
|
||||
@@ -113,8 +110,8 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface
|
||||
/**
|
||||
* Creates a new sheet in the workbook. The current sheet remains unchanged.
|
||||
*
|
||||
* @return Worksheet The created sheet
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to open the sheet for writing
|
||||
* @return Worksheet The created sheet
|
||||
*/
|
||||
private function addNewSheet()
|
||||
{
|
||||
@@ -158,8 +155,8 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface
|
||||
* The writing will resume where it stopped (i.e. data won't be truncated).
|
||||
*
|
||||
* @param Sheet $sheet The "external" sheet to set as current
|
||||
* @return void
|
||||
* @throws SheetNotFoundException If the given sheet does not exist in the workbook
|
||||
* @return void
|
||||
*/
|
||||
public function setCurrentSheet(Sheet $sheet)
|
||||
{
|
||||
@@ -208,9 +205,9 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface
|
||||
* @param array $dataRow Array containing data to be written. Cannot be empty.
|
||||
* Example $dataRow = ['data1', 1234, null, '', 'data5'];
|
||||
* @param Style $style Style to be applied to the row.
|
||||
* @return void
|
||||
* @throws IOException If trying to create a new sheet and unable to open the sheet for writing
|
||||
* @throws WriterException If unable to write data
|
||||
* @return void
|
||||
*/
|
||||
public function addRowToCurrentWorksheet($dataRow, Style $style)
|
||||
{
|
||||
@@ -238,6 +235,7 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface
|
||||
private function hasCurrentWorkseetReachedMaxRows()
|
||||
{
|
||||
$currentWorksheet = $this->getCurrentWorksheet();
|
||||
|
||||
return ($currentWorksheet->getLastWrittenRowIndex() >= $this->getMaxRowsPerWorksheet());
|
||||
}
|
||||
|
||||
@@ -248,8 +246,8 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface
|
||||
* @param array $dataRow Array containing data to be written. Cannot be empty.
|
||||
* Example $dataRow = ['data1', 1234, null, '', 'data5'];
|
||||
* @param Style $style Style to be applied to the row.
|
||||
* @return void
|
||||
* @throws WriterException If unable to write data
|
||||
* @return void
|
||||
*/
|
||||
private function addRowWithStyleToWorksheet(Worksheet $worksheet, $dataRow, Style $style)
|
||||
{
|
||||
|
||||
@@ -4,17 +4,15 @@ namespace Box\Spout\Writer\Common\Manager;
|
||||
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
use Box\Spout\Writer\Common\Entity\Sheet;
|
||||
use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
use Box\Spout\Writer\Common\Entity\Workbook;
|
||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||
use Box\Spout\Writer\Exception\SheetNotFoundException;
|
||||
use Box\Spout\Writer\Exception\WriterException;
|
||||
use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
|
||||
/**
|
||||
* Interface WorkbookManagerInterface
|
||||
* workbook manager interface, providing the generic interfaces to work with workbook.
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Manager
|
||||
*/
|
||||
interface WorkbookManagerInterface
|
||||
{
|
||||
@@ -27,8 +25,8 @@ interface WorkbookManagerInterface
|
||||
* Creates a new sheet in the workbook and make it the current sheet.
|
||||
* The writing will resume where it stopped (i.e. data won't be truncated).
|
||||
*
|
||||
* @return Worksheet The created sheet
|
||||
* @throws IOException If unable to open the sheet for writing
|
||||
* @return Worksheet The created sheet
|
||||
*/
|
||||
public function addNewSheetAndMakeItCurrent();
|
||||
|
||||
@@ -49,8 +47,8 @@ interface WorkbookManagerInterface
|
||||
* The writing will resume where it stopped (i.e. data won't be truncated).
|
||||
*
|
||||
* @param Sheet $sheet The "external" sheet to set as current
|
||||
* @return void
|
||||
* @throws SheetNotFoundException If the given sheet does not exist in the workbook
|
||||
* @return void
|
||||
*/
|
||||
public function setCurrentSheet(Sheet $sheet);
|
||||
|
||||
@@ -62,9 +60,9 @@ interface WorkbookManagerInterface
|
||||
* @param array $dataRow Array containing data to be written. Cannot be empty.
|
||||
* Example $dataRow = ['data1', 1234, null, '', 'data5'];
|
||||
* @param Style $style Style to be applied to the row.
|
||||
* @return void
|
||||
* @throws IOException If trying to create a new sheet and unable to open the sheet for writing
|
||||
* @throws WriterException If unable to write data
|
||||
* @return void
|
||||
*/
|
||||
public function addRowToCurrentWorksheet($dataRow, Style $style);
|
||||
|
||||
@@ -77,4 +75,4 @@ interface WorkbookManagerInterface
|
||||
* @return void
|
||||
*/
|
||||
public function close($finalFilePointer);
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,12 @@
|
||||
|
||||
namespace Box\Spout\Writer\Common\Manager;
|
||||
|
||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||
use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||
|
||||
/**
|
||||
* Interface WorksheetManagerInterface
|
||||
* Inteface for worksheet managers, providing the generic interfaces to work with worksheets.
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Manager
|
||||
*/
|
||||
interface WorksheetManagerInterface
|
||||
{
|
||||
@@ -20,9 +18,9 @@ interface WorksheetManagerInterface
|
||||
* @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 \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
|
||||
*/
|
||||
public function addRow(Worksheet $worksheet, $dataRow, $rowStyle);
|
||||
|
||||
@@ -30,8 +28,8 @@ interface WorksheetManagerInterface
|
||||
* 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);
|
||||
|
||||
@@ -42,4 +40,4 @@ interface WorksheetManagerInterface
|
||||
* @return void
|
||||
*/
|
||||
public function close(Worksheet $worksheet);
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace Box\Spout\Writer\Exception\Border;
|
||||
|
||||
use Box\Spout\Writer\Exception\WriterException;
|
||||
use Box\Spout\Writer\Common\Entity\Style\BorderPart;
|
||||
use Box\Spout\Writer\Exception\WriterException;
|
||||
|
||||
class InvalidNameException extends WriterException
|
||||
{
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace Box\Spout\Writer\Exception\Border;
|
||||
|
||||
use Box\Spout\Writer\Exception\WriterException;
|
||||
use Box\Spout\Writer\Common\Entity\Style\BorderPart;
|
||||
use Box\Spout\Writer\Exception\WriterException;
|
||||
|
||||
class InvalidStyleException extends WriterException
|
||||
{
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace Box\Spout\Writer\Exception\Border;
|
||||
|
||||
use Box\Spout\Writer\Exception\WriterException;
|
||||
use Box\Spout\Writer\Common\Entity\Style\BorderPart;
|
||||
use Box\Spout\Writer\Exception\WriterException;
|
||||
|
||||
class InvalidWidthException extends WriterException
|
||||
{
|
||||
|
||||
@@ -6,7 +6,6 @@ namespace Box\Spout\Writer\Exception;
|
||||
* Class InvalidColorException
|
||||
*
|
||||
* @api
|
||||
* @package Box\Spout\Writer\Exception
|
||||
*/
|
||||
class InvalidColorException extends WriterException
|
||||
{
|
||||
|
||||
@@ -6,7 +6,6 @@ namespace Box\Spout\Writer\Exception;
|
||||
* Class InvalidSheetNameException
|
||||
*
|
||||
* @api
|
||||
* @package Box\Spout\Writer\Exception
|
||||
*/
|
||||
class InvalidSheetNameException extends WriterException
|
||||
{
|
||||
|
||||
@@ -6,7 +6,6 @@ namespace Box\Spout\Writer\Exception;
|
||||
* Class SheetNotFoundException
|
||||
*
|
||||
* @api
|
||||
* @package Box\Spout\Writer\Exception
|
||||
*/
|
||||
class SheetNotFoundException extends WriterException
|
||||
{
|
||||
|
||||
@@ -6,7 +6,6 @@ namespace Box\Spout\Writer\Exception;
|
||||
* Class WriterAlreadyOpenedException
|
||||
*
|
||||
* @api
|
||||
* @package Box\Spout\Writer\Exception
|
||||
*/
|
||||
class WriterAlreadyOpenedException extends WriterException
|
||||
{
|
||||
|
||||
@@ -7,7 +7,6 @@ use Box\Spout\Common\Exception\SpoutException;
|
||||
/**
|
||||
* Class WriterException
|
||||
*
|
||||
* @package Box\Spout\Writer\Exception
|
||||
* @abstract
|
||||
*/
|
||||
abstract class WriterException extends SpoutException
|
||||
|
||||
@@ -6,7 +6,6 @@ namespace Box\Spout\Writer\Exception;
|
||||
* Class WriterNotOpenedException
|
||||
*
|
||||
* @api
|
||||
* @package Box\Spout\Writer\Exception
|
||||
*/
|
||||
class WriterNotOpenedException extends WriterException
|
||||
{
|
||||
|
||||
@@ -2,19 +2,17 @@
|
||||
|
||||
namespace Box\Spout\Writer\ODS\Creator;
|
||||
|
||||
use Box\Spout\Common\Helper\StringHelper;
|
||||
use Box\Spout\Writer\Common\Helper\ZipHelper;
|
||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Writer\Common\Creator\EntityFactory;
|
||||
use Box\Spout\Writer\ODS\Helper\FileSystemHelper;
|
||||
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\Writer\ODS\Helper\FileSystemHelper;
|
||||
|
||||
/**
|
||||
* Class HelperFactory
|
||||
* Factory for helpers needed by the ODS Writer
|
||||
*
|
||||
* @package Box\Spout\Writer\ODS\Creator
|
||||
*/
|
||||
class HelperFactory extends \Box\Spout\Common\Creator\HelperFactory
|
||||
{
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace Box\Spout\Writer\ODS\Creator;
|
||||
|
||||
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\Creator\ManagerFactoryInterface;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Writer\Common\Manager\SheetManager;
|
||||
use Box\Spout\Writer\ODS\Manager\Style\StyleManager;
|
||||
use Box\Spout\Writer\ODS\Manager\Style\StyleRegistry;
|
||||
@@ -15,8 +15,6 @@ use Box\Spout\Writer\ODS\Manager\WorksheetManager;
|
||||
/**
|
||||
* Class ManagerFactory
|
||||
* Factory for managers needed by the ODS Writer
|
||||
*
|
||||
* @package Box\Spout\Writer\ODS\Creator
|
||||
*/
|
||||
class ManagerFactory implements ManagerFactoryInterface
|
||||
{
|
||||
@@ -78,6 +76,7 @@ class ManagerFactory implements ManagerFactoryInterface
|
||||
public function createSheetManager()
|
||||
{
|
||||
$stringHelper = $this->helperFactory->createStringHelper();
|
||||
|
||||
return new SheetManager($stringHelper);
|
||||
}
|
||||
|
||||
@@ -88,6 +87,7 @@ class ManagerFactory implements ManagerFactoryInterface
|
||||
private function createStyleManager(OptionsManagerInterface $optionsManager)
|
||||
{
|
||||
$styleRegistry = $this->createStyleRegistry($optionsManager);
|
||||
|
||||
return new StyleManager($styleRegistry);
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@ class ManagerFactory implements ManagerFactoryInterface
|
||||
private function createStyleRegistry(OptionsManagerInterface $optionsManager)
|
||||
{
|
||||
$defaultRowStyle = $optionsManager->getOption(Options::DEFAULT_ROW_STYLE);
|
||||
|
||||
return new StyleRegistry($defaultRowStyle);
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace Box\Spout\Writer\ODS\Helper;
|
||||
|
||||
use Box\Spout\Writer\Common\Entity\Style\BorderPart;
|
||||
use Box\Spout\Writer\Common\Entity\Style\Border;
|
||||
use Box\Spout\Writer\Common\Entity\Style\BorderPart;
|
||||
|
||||
/**
|
||||
* Class BorderHelper
|
||||
@@ -27,9 +27,9 @@ class BorderHelper
|
||||
* @var array
|
||||
*/
|
||||
protected static $widthMap = [
|
||||
Border::WIDTH_THIN => '0.75pt',
|
||||
Border::WIDTH_THIN => '0.75pt',
|
||||
Border::WIDTH_MEDIUM => '1.75pt',
|
||||
Border::WIDTH_THICK => '2.5pt',
|
||||
Border::WIDTH_THICK => '2.5pt',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ class BorderHelper
|
||||
* @var array
|
||||
*/
|
||||
protected static $styleMap = [
|
||||
Border::STYLE_SOLID => 'solid',
|
||||
Border::STYLE_SOLID => 'solid',
|
||||
Border::STYLE_DASHED => 'dashed',
|
||||
Border::STYLE_DOTTED => 'dotted',
|
||||
Border::STYLE_DOUBLE => 'double',
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Box\Spout\Writer\ODS\Helper;
|
||||
|
||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||
use Box\Spout\Writer\Common\Helper\FileSystemWithRootFolderHelperInterface;
|
||||
use Box\Spout\Writer\Common\Helper\ZipHelper;
|
||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||
use Box\Spout\Writer\ODS\Manager\Style\StyleManager;
|
||||
use Box\Spout\Writer\ODS\Manager\WorksheetManager;
|
||||
|
||||
@@ -12,8 +12,6 @@ use Box\Spout\Writer\ODS\Manager\WorksheetManager;
|
||||
* Class FileSystemHelper
|
||||
* This class provides helper functions to help with the file system operations
|
||||
* like files/folders creation & deletion for ODS files
|
||||
*
|
||||
* @package Box\Spout\Writer\ODS\Helper
|
||||
*/
|
||||
class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper implements FileSystemWithRootFolderHelperInterface
|
||||
{
|
||||
@@ -70,8 +68,8 @@ class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper impleme
|
||||
/**
|
||||
* Creates all the folders needed to create a ODS 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()
|
||||
{
|
||||
@@ -86,20 +84,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
|
||||
*/
|
||||
protected function createRootFolder()
|
||||
{
|
||||
$this->rootFolder = $this->createFolder($this->baseFolderRealPath, uniqid('ods'));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the "META-INF" folder under the root folder as well as the "manifest.xml" file in it
|
||||
*
|
||||
* @return FileSystemHelper
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or the "manifest.xml" file
|
||||
* @return FileSystemHelper
|
||||
*/
|
||||
protected function createMetaInfoFolderAndFile()
|
||||
{
|
||||
@@ -113,12 +112,12 @@ class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper impleme
|
||||
/**
|
||||
* Creates the "manifest.xml" file under the "META-INF" folder (under root)
|
||||
*
|
||||
* @return FileSystemHelper
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to create the file
|
||||
* @return FileSystemHelper
|
||||
*/
|
||||
protected function createManifestFile()
|
||||
{
|
||||
$manifestXmlFileContents = <<<EOD
|
||||
$manifestXmlFileContents = <<<'EOD'
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2">
|
||||
<manifest:file-entry manifest:full-path="/" manifest:media-type="application/vnd.oasis.opendocument.spreadsheet"/>
|
||||
@@ -137,20 +136,21 @@ EOD;
|
||||
* Creates the temp folder where specific sheets content will be written to.
|
||||
* This folder is not part of the final ODS file and is only used to be able to jump between sheets.
|
||||
*
|
||||
* @return FileSystemHelper
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to create the folder
|
||||
* @return FileSystemHelper
|
||||
*/
|
||||
protected function createSheetsContentTempFolder()
|
||||
{
|
||||
$this->sheetsContentTempFolder = $this->createFolder($this->rootFolder, self::SHEETS_CONTENT_TEMP_FOLDER_NAME);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the "meta.xml" file under the root folder
|
||||
*
|
||||
* @return FileSystemHelper
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to create the file
|
||||
* @return FileSystemHelper
|
||||
*/
|
||||
protected function createMetaFile()
|
||||
{
|
||||
@@ -176,12 +176,13 @@ EOD;
|
||||
/**
|
||||
* Creates the "mimetype" file under the root folder
|
||||
*
|
||||
* @return FileSystemHelper
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to create the file
|
||||
* @return FileSystemHelper
|
||||
*/
|
||||
protected function createMimetypeFile()
|
||||
{
|
||||
$this->createFileWithContents($this->rootFolder, self::MIMETYPE_FILE_NAME, self::MIMETYPE);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -195,7 +196,7 @@ EOD;
|
||||
*/
|
||||
public function createContentFile($worksheetManager, $styleManager, $worksheets)
|
||||
{
|
||||
$contentXmlFileContents = <<<EOD
|
||||
$contentXmlFileContents = <<<'EOD'
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<office:document-content office:version="1.2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:msoxl="http://schemas.microsoft.com/office/excel/formula" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
EOD;
|
||||
@@ -253,10 +254,10 @@ EOD;
|
||||
public function deleteWorksheetTempFolder()
|
||||
{
|
||||
$this->deleteFolderRecursively($this->sheetsContentTempFolder);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates the "styles.xml" file under the root folder
|
||||
*
|
||||
|
||||
@@ -2,15 +2,13 @@
|
||||
|
||||
namespace Box\Spout\Writer\ODS\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
|
||||
* ODS Writer options manager
|
||||
*
|
||||
* @package Box\Spout\Writer\ODS\Manager
|
||||
*/
|
||||
class OptionsManager extends OptionsManagerAbstract
|
||||
{
|
||||
@@ -28,7 +26,7 @@ class OptionsManager extends OptionsManagerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getSupportedOptions()
|
||||
{
|
||||
@@ -40,7 +38,7 @@ class OptionsManager extends OptionsManagerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDefaultOptions()
|
||||
{
|
||||
|
||||
@@ -8,8 +8,6 @@ use Box\Spout\Writer\ODS\Helper\BorderHelper;
|
||||
/**
|
||||
* Class StyleManager
|
||||
* Manages styles to be applied to a cell
|
||||
*
|
||||
* @package Box\Spout\Writer\ODS\Manager\Style
|
||||
*/
|
||||
class StyleManager extends \Box\Spout\Writer\Common\Manager\Style\StyleManager
|
||||
{
|
||||
@@ -24,7 +22,7 @@ class StyleManager extends \Box\Spout\Writer\Common\Manager\Style\StyleManager
|
||||
*/
|
||||
public function getStylesXMLFileContent($numWorksheets)
|
||||
{
|
||||
$content = <<<EOD
|
||||
$content = <<<'EOD'
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<office:document-styles office:version="1.2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:msoxl="http://schemas.microsoft.com/office/excel/formula" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
EOD;
|
||||
@@ -34,7 +32,7 @@ EOD;
|
||||
$content .= $this->getAutomaticStylesSectionContent($numWorksheets);
|
||||
$content .= $this->getMasterStylesSectionContent($numWorksheets);
|
||||
|
||||
$content .= <<<EOD
|
||||
$content .= <<<'EOD'
|
||||
</office:document-styles>
|
||||
EOD;
|
||||
|
||||
@@ -132,7 +130,6 @@ EOD;
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the contents of the "<office:font-face-decls>" section, inside "content.xml" file.
|
||||
*
|
||||
@@ -163,7 +160,7 @@ EOD;
|
||||
$content .= $this->getStyleSectionContent($style);
|
||||
}
|
||||
|
||||
$content .= <<<EOD
|
||||
$content .= <<<'EOD'
|
||||
<style:style style:family="table-column" style:name="co1">
|
||||
<style:table-column-properties fo:break-before="auto"/>
|
||||
</style:style>
|
||||
|
||||
@@ -7,8 +7,6 @@ use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
/**
|
||||
* Class StyleRegistry
|
||||
* Registry for all used styles
|
||||
*
|
||||
* @package Box\Spout\Writer\ODS\Manager\Style
|
||||
*/
|
||||
class StyleRegistry extends \Box\Spout\Writer\Common\Manager\Style\StyleRegistry
|
||||
{
|
||||
|
||||
@@ -10,8 +10,6 @@ use Box\Spout\Writer\ODS\Manager\Style\StyleManager;
|
||||
/**
|
||||
* Class WorkbookManager
|
||||
* ODS workbook manager, providing the interfaces to work with workbook.
|
||||
*
|
||||
* @package Box\Spout\Writer\ODS\Manager
|
||||
*/
|
||||
class WorkbookManager extends WorkbookManagerAbstract
|
||||
{
|
||||
@@ -45,6 +43,7 @@ class WorkbookManager extends WorkbookManagerAbstract
|
||||
public function getWorksheetFilePath(Sheet $sheet)
|
||||
{
|
||||
$sheetsContentTempFolder = $this->fileSystemHelper->getSheetsContentTempFolder();
|
||||
|
||||
return $sheetsContentTempFolder . '/sheet' . $sheet->getIndex() . '.xml';
|
||||
}
|
||||
|
||||
@@ -65,4 +64,4 @@ class WorkbookManager extends WorkbookManagerAbstract
|
||||
->createStylesFile($this->styleManager, $numWorksheets)
|
||||
->zipRootFolderAndCopyToStream($finalFilePointer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,16 +7,13 @@ use Box\Spout\Common\Exception\IOException;
|
||||
use Box\Spout\Common\Helper\StringHelper;
|
||||
use Box\Spout\Writer\Common\Creator\EntityFactory;
|
||||
use Box\Spout\Writer\Common\Entity\Cell;
|
||||
use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||
use Box\Spout\Writer\Common\Manager\WorksheetManagerInterface;
|
||||
use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
use Box\Spout\Writer\ODS\Manager\Style\StyleManager;
|
||||
|
||||
/**
|
||||
* Class WorksheetManager
|
||||
* ODS worksheet manager, providing the interfaces to work with ODS worksheets.
|
||||
*
|
||||
* @package Box\Spout\Writer\ODS\Manager
|
||||
*/
|
||||
class WorksheetManager implements WorksheetManagerInterface
|
||||
{
|
||||
@@ -39,8 +36,8 @@ class WorksheetManager implements WorksheetManagerInterface
|
||||
public function __construct(
|
||||
\Box\Spout\Common\Helper\Escaper\ODS $stringsEscaper,
|
||||
StringHelper $stringHelper,
|
||||
EntityFactory $entityFactory)
|
||||
{
|
||||
EntityFactory $entityFactory
|
||||
) {
|
||||
$this->stringsEscaper = $stringsEscaper;
|
||||
$this->stringHelper = $stringHelper;
|
||||
$this->entityFactory = $entityFactory;
|
||||
@@ -50,8 +47,8 @@ class WorksheetManager implements WorksheetManagerInterface
|
||||
* 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)
|
||||
{
|
||||
@@ -65,8 +62,8 @@ class WorksheetManager implements WorksheetManagerInterface
|
||||
* 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)
|
||||
{
|
||||
@@ -100,9 +97,9 @@ class WorksheetManager implements WorksheetManagerInterface
|
||||
* @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)
|
||||
{
|
||||
@@ -124,7 +121,6 @@ class WorksheetManager implements WorksheetManagerInterface
|
||||
// Using isset here because it is way faster than array_key_exists...
|
||||
if (!isset($dataRowWithNumericIndexes[$nextCellIndex]) ||
|
||||
$currentCellValue !== $dataRowWithNumericIndexes[$nextCellIndex]) {
|
||||
|
||||
$numTimesValueRepeated = ($nextCellIndex - $currentCellIndex);
|
||||
$data .= $this->getCellXML($currentCellValue, $styleIndex, $numTimesValueRepeated);
|
||||
|
||||
@@ -152,8 +148,8 @@ class WorksheetManager implements WorksheetManagerInterface
|
||||
* @param mixed $cellValue The value to be written
|
||||
* @param int $styleIndex Index of the used style
|
||||
* @param int $numTimesValueRepeated Number of times the value is consecutively repeated
|
||||
* @return string The cell XML content
|
||||
* @throws \Box\Spout\Common\Exception\InvalidArgumentException If a cell value's type is not supported
|
||||
* @return string The cell XML content
|
||||
*/
|
||||
private function getCellXML($cellValue, $styleIndex, $numTimesValueRepeated)
|
||||
{
|
||||
@@ -163,7 +159,7 @@ class WorksheetManager implements WorksheetManagerInterface
|
||||
$data .= ' table:number-columns-repeated="' . $numTimesValueRepeated . '"';
|
||||
}
|
||||
|
||||
/** @TODO Remove code duplication with XLSX writer: https://github.com/box/spout/pull/383#discussion_r113292746 */
|
||||
/* @TODO Remove code duplication with XLSX writer: https://github.com/box/spout/pull/383#discussion_r113292746 */
|
||||
if ($cellValue instanceof Cell) {
|
||||
$cell = $cellValue;
|
||||
} else {
|
||||
@@ -179,15 +175,15 @@ class WorksheetManager implements WorksheetManagerInterface
|
||||
}
|
||||
|
||||
$data .= '</table:table-cell>';
|
||||
} else if ($cell->isBoolean()) {
|
||||
} elseif ($cell->isBoolean()) {
|
||||
$data .= ' office:value-type="boolean" calcext:value-type="boolean" office:boolean-value="' . $cell->getValue() . '">';
|
||||
$data .= '<text:p>' . $cell->getValue() . '</text:p>';
|
||||
$data .= '</table:table-cell>';
|
||||
} else if ($cell->isNumeric()) {
|
||||
} elseif ($cell->isNumeric()) {
|
||||
$data .= ' office:value-type="float" calcext:value-type="float" office:value="' . $cell->getValue() . '">';
|
||||
$data .= '<text:p>' . $cell->getValue() . '</text:p>';
|
||||
$data .= '</table:table-cell>';
|
||||
} else if ($cell->isEmpty()) {
|
||||
} elseif ($cell->isEmpty()) {
|
||||
$data .= '/>';
|
||||
} else {
|
||||
throw new InvalidArgumentException('Trying to add a value with an unsupported type: ' . gettype($cell->getValue()));
|
||||
|
||||
@@ -8,8 +8,6 @@ use Box\Spout\Writer\WriterMultiSheetsAbstract;
|
||||
/**
|
||||
* Class Writer
|
||||
* This class provides base support to write data to ODS files
|
||||
*
|
||||
* @package Box\Spout\Writer\ODS
|
||||
*/
|
||||
class Writer extends WriterMultiSheetsAbstract
|
||||
{
|
||||
@@ -22,14 +20,15 @@ class Writer extends WriterMultiSheetsAbstract
|
||||
*
|
||||
* @api
|
||||
* @param string $tempFolder Temporary folder where the files to create the ODS 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;
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,9 @@ use Box\Spout\Common\Exception\InvalidArgumentException;
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
use Box\Spout\Common\Exception\SpoutException;
|
||||
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
|
||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
|
||||
use Box\Spout\Writer\Exception\WriterAlreadyOpenedException;
|
||||
use Box\Spout\Writer\Exception\WriterNotOpenedException;
|
||||
@@ -17,7 +17,6 @@ use Box\Spout\Writer\Exception\WriterNotOpenedException;
|
||||
/**
|
||||
* Class WriterAbstract
|
||||
*
|
||||
* @package Box\Spout\Writer
|
||||
* @abstract
|
||||
*/
|
||||
abstract class WriterAbstract implements WriterInterface
|
||||
@@ -59,8 +58,8 @@ abstract class WriterAbstract implements WriterInterface
|
||||
OptionsManagerInterface $optionsManager,
|
||||
StyleMerger $styleMerger,
|
||||
GlobalFunctionsHelper $globalFunctionsHelper,
|
||||
HelperFactory $helperFactory)
|
||||
{
|
||||
HelperFactory $helperFactory
|
||||
) {
|
||||
$this->optionsManager = $optionsManager;
|
||||
$this->styleMerger = $styleMerger;
|
||||
$this->globalFunctionsHelper = $globalFunctionsHelper;
|
||||
@@ -72,8 +71,8 @@ abstract class WriterAbstract implements WriterInterface
|
||||
/**
|
||||
* Opens the streamer and makes it ready to accept data.
|
||||
*
|
||||
* @return void
|
||||
* @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function openWriter();
|
||||
|
||||
@@ -106,6 +105,7 @@ abstract class WriterAbstract implements WriterInterface
|
||||
{
|
||||
$this->optionsManager->setOption(Options::DEFAULT_ROW_STYLE, $defaultStyle);
|
||||
$this->resetRowStyleToDefault();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -115,8 +115,8 @@ abstract class WriterAbstract implements WriterInterface
|
||||
*
|
||||
* @api
|
||||
* @param string $outputFilePath Path of the output file that will contain the data
|
||||
* @return WriterAbstract
|
||||
* @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened or if the given path is not writable
|
||||
* @return WriterAbstract
|
||||
*/
|
||||
public function openToFile($outputFilePath)
|
||||
{
|
||||
@@ -139,8 +139,8 @@ abstract class WriterAbstract implements WriterInterface
|
||||
*
|
||||
* @api
|
||||
* @param string $outputFileName Name of the output file that will contain the data. If a path is passed in, only the file name will be kept
|
||||
* @return WriterAbstract
|
||||
* @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened
|
||||
* @return WriterAbstract
|
||||
*/
|
||||
public function openToBrowser($outputFileName)
|
||||
{
|
||||
@@ -177,8 +177,8 @@ abstract class WriterAbstract implements WriterInterface
|
||||
* Checks if the pointer to the file/stream to write to is available.
|
||||
* Will throw an exception if not available.
|
||||
*
|
||||
* @return void
|
||||
* @throws \Box\Spout\Common\Exception\IOException If the pointer is not available
|
||||
* @return void
|
||||
*/
|
||||
protected function throwIfFilePointerIsNotAvailable()
|
||||
{
|
||||
@@ -192,8 +192,8 @@ abstract class WriterAbstract implements WriterInterface
|
||||
* Throws an exception if already opened.
|
||||
*
|
||||
* @param string $message Error message
|
||||
* @return void
|
||||
* @throws \Box\Spout\Writer\Exception\WriterAlreadyOpenedException If the writer was already opened and must not be.
|
||||
* @return void
|
||||
*/
|
||||
protected function throwIfWriterAlreadyOpened($message)
|
||||
{
|
||||
@@ -209,10 +209,10 @@ abstract class WriterAbstract implements WriterInterface
|
||||
* If empty, no data is added (i.e. not even as a blank row)
|
||||
* Example: $dataRow = ['data1', 1234, null, '', 'data5', false];
|
||||
* @api
|
||||
* @return WriterAbstract
|
||||
* @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If this function is called before opening the writer
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to write data
|
||||
* @throws \Box\Spout\Common\Exception\SpoutException If anything else goes wrong while writing data
|
||||
* @return WriterAbstract
|
||||
*/
|
||||
public function addRow(array $dataRow)
|
||||
{
|
||||
@@ -244,10 +244,10 @@ abstract class WriterAbstract implements WriterInterface
|
||||
* @api
|
||||
* @param array $dataRow Array of array containing data to be streamed.
|
||||
* @param Style $style Style to be applied to the row.
|
||||
* @return WriterAbstract
|
||||
* @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid
|
||||
* @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If this function is called before opening the writer
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to write data
|
||||
* @return WriterAbstract
|
||||
*/
|
||||
public function addRowWithStyle(array $dataRow, $style)
|
||||
{
|
||||
@@ -272,10 +272,10 @@ abstract class WriterAbstract implements WriterInterface
|
||||
* ['data11', 12, , '', 'data13'],
|
||||
* ['data21', 'data22', null, false],
|
||||
* ];
|
||||
* @return WriterAbstract
|
||||
* @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid
|
||||
* @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If this function is called before opening the writer
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to write data
|
||||
* @return WriterAbstract
|
||||
*/
|
||||
public function addRows(array $dataRows)
|
||||
{
|
||||
@@ -300,10 +300,10 @@ abstract class WriterAbstract implements WriterInterface
|
||||
* @api
|
||||
* @param array $dataRows Array of array containing data to be streamed.
|
||||
* @param Style $style Style to be applied to the rows.
|
||||
* @return WriterAbstract
|
||||
* @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid
|
||||
* @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If this function is called before opening the writer
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to write data
|
||||
* @return WriterAbstract
|
||||
*/
|
||||
public function addRowsWithStyle(array $dataRows, $style)
|
||||
{
|
||||
|
||||
@@ -14,8 +14,6 @@ use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
|
||||
* Class WriterFactory
|
||||
* This factory is used to create writers, based on the type of the file to be read.
|
||||
* It supports CSV, XLSX and ODS formats.
|
||||
*
|
||||
* @package Box\Spout\Writer
|
||||
*/
|
||||
class WriterFactory
|
||||
{
|
||||
@@ -24,8 +22,8 @@ class WriterFactory
|
||||
*
|
||||
* @api
|
||||
* @param string $writerType Type of the writer to instantiate
|
||||
* @return WriterInterface
|
||||
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException
|
||||
* @return WriterInterface
|
||||
*/
|
||||
public static function create($writerType)
|
||||
{
|
||||
|
||||
@@ -6,8 +6,6 @@ use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
|
||||
/**
|
||||
* Interface WriterInterface
|
||||
*
|
||||
* @package Box\Spout\Writer
|
||||
*/
|
||||
interface WriterInterface
|
||||
{
|
||||
@@ -16,8 +14,8 @@ interface WriterInterface
|
||||
* By using this method, the data will be written to a file.
|
||||
*
|
||||
* @param string $outputFilePath Path of the output file that will contain the data
|
||||
* @return WriterInterface
|
||||
* @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened or if the given path is not writable
|
||||
* @return WriterInterface
|
||||
*/
|
||||
public function openToFile($outputFilePath);
|
||||
|
||||
@@ -26,8 +24,8 @@ interface WriterInterface
|
||||
* By using this method, the data will be outputted directly to the browser.
|
||||
*
|
||||
* @param string $outputFileName Name of the output file that will contain the data. If a path is passed in, only the file name will be kept
|
||||
* @return WriterInterface
|
||||
* @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened
|
||||
* @return WriterInterface
|
||||
*/
|
||||
public function openToBrowser($outputFileName);
|
||||
|
||||
@@ -36,9 +34,9 @@ interface WriterInterface
|
||||
*
|
||||
* @param array $dataRow Array containing data to be streamed.
|
||||
* Example $dataRow = ['data1', 1234, null, '', 'data5'];
|
||||
* @return WriterInterface
|
||||
* @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If the writer has not been opened yetthe writer
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to write data
|
||||
* @return WriterInterface
|
||||
*/
|
||||
public function addRow(array $dataRow);
|
||||
|
||||
@@ -48,10 +46,10 @@ interface WriterInterface
|
||||
*
|
||||
* @param array $dataRow Array of array containing data to be streamed.
|
||||
* @param Style $style Style to be applied to the row.
|
||||
* @return WriterInterface
|
||||
* @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid
|
||||
* @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If this function is called before opening the writer
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to write data
|
||||
* @return WriterInterface
|
||||
*/
|
||||
public function addRowWithStyle(array $dataRow, $style);
|
||||
|
||||
@@ -63,10 +61,10 @@ interface WriterInterface
|
||||
* ['data11', 12, , '', 'data13'],
|
||||
* ['data21', 'data22', null],
|
||||
* ];
|
||||
* @return WriterInterface
|
||||
* @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid
|
||||
* @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If the writer has not been opened yet
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to write data
|
||||
* @return WriterInterface
|
||||
*/
|
||||
public function addRows(array $dataRows);
|
||||
|
||||
@@ -76,10 +74,10 @@ interface WriterInterface
|
||||
*
|
||||
* @param array $dataRows Array of array containing data to be streamed.
|
||||
* @param Style $style Style to be applied to the rows.
|
||||
* @return WriterInterface
|
||||
* @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid
|
||||
* @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If this function is called before opening the writer
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to write data
|
||||
* @return WriterInterface
|
||||
*/
|
||||
public function addRowsWithStyle(array $dataRows, $style);
|
||||
|
||||
|
||||
@@ -4,21 +4,20 @@ namespace Box\Spout\Writer;
|
||||
|
||||
use Box\Spout\Common\Creator\HelperFactory;
|
||||
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
|
||||
use Box\Spout\Writer\Common\Entity\Sheet;
|
||||
use Box\Spout\Common\Manager\OptionsManagerInterface;
|
||||
use Box\Spout\Writer\Common\Creator\ManagerFactoryInterface;
|
||||
use Box\Spout\Writer\Common\Entity\Options;
|
||||
use Box\Spout\Writer\Common\Entity\Sheet;
|
||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
|
||||
use Box\Spout\Writer\Common\Manager\WorkbookManagerInterface;
|
||||
use Box\Spout\Writer\Exception\SheetNotFoundException;
|
||||
use Box\Spout\Writer\Exception\WriterAlreadyOpenedException;
|
||||
use Box\Spout\Writer\Exception\WriterNotOpenedException;
|
||||
use Box\Spout\Writer\Common\Creator\ManagerFactoryInterface;
|
||||
use Box\Spout\Writer\Common\Manager\WorkbookManagerInterface;
|
||||
|
||||
/**
|
||||
* Class WriterMultiSheetsAbstract
|
||||
*
|
||||
* @package Box\Spout\Writer
|
||||
* @abstract
|
||||
*/
|
||||
abstract class WriterMultiSheetsAbstract extends WriterAbstract
|
||||
@@ -41,8 +40,8 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract
|
||||
StyleMerger $styleMerger,
|
||||
GlobalFunctionsHelper $globalFunctionsHelper,
|
||||
HelperFactory $helperFactory,
|
||||
ManagerFactoryInterface $managerFactory)
|
||||
{
|
||||
ManagerFactoryInterface $managerFactory
|
||||
) {
|
||||
parent::__construct($optionsManager, $styleMerger, $globalFunctionsHelper, $helperFactory);
|
||||
$this->managerFactory = $managerFactory;
|
||||
}
|
||||
@@ -53,22 +52,23 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract
|
||||
*
|
||||
* @api
|
||||
* @param bool $shouldCreateNewSheetsAutomatically Whether new sheets should be automatically created when the max rows limit per sheet is reached
|
||||
* @return WriterMultiSheetsAbstract
|
||||
* @throws WriterAlreadyOpenedException If the writer was already opened
|
||||
* @return WriterMultiSheetsAbstract
|
||||
*/
|
||||
public function setShouldCreateNewSheetsAutomatically($shouldCreateNewSheetsAutomatically)
|
||||
{
|
||||
$this->throwIfWriterAlreadyOpened('Writer must be configured before opening it.');
|
||||
|
||||
$this->optionsManager->setOption(Options::SHOULD_CREATE_NEW_SHEETS_AUTOMATICALLY, $shouldCreateNewSheetsAutomatically);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the write and sets the current sheet pointer to a new sheet.
|
||||
*
|
||||
* @return void
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to open the file for writing
|
||||
* @return void
|
||||
*/
|
||||
protected function openWriter()
|
||||
{
|
||||
@@ -82,8 +82,8 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract
|
||||
* Returns all the workbook's sheets
|
||||
*
|
||||
* @api
|
||||
* @return Sheet[] All the workbook's sheets
|
||||
* @throws WriterNotOpenedException If the writer has not been opened yet
|
||||
* @return Sheet[] All the workbook's sheets
|
||||
*/
|
||||
public function getSheets()
|
||||
{
|
||||
@@ -104,8 +104,8 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract
|
||||
* Creates a new sheet and make it the current sheet. The data will now be written to this sheet.
|
||||
*
|
||||
* @api
|
||||
* @return Sheet The created sheet
|
||||
* @throws WriterNotOpenedException If the writer has not been opened yet
|
||||
* @return Sheet The created sheet
|
||||
*/
|
||||
public function addNewSheetAndMakeItCurrent()
|
||||
{
|
||||
@@ -119,12 +119,13 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract
|
||||
* Returns the current sheet
|
||||
*
|
||||
* @api
|
||||
* @return Sheet The current sheet
|
||||
* @throws WriterNotOpenedException If the writer has not been opened yet
|
||||
* @return Sheet The current sheet
|
||||
*/
|
||||
public function getCurrentSheet()
|
||||
{
|
||||
$this->throwIfWorkbookIsNotAvailable();
|
||||
|
||||
return $this->workbookManager->getCurrentWorksheet()->getExternalSheet();
|
||||
}
|
||||
|
||||
@@ -134,9 +135,9 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract
|
||||
*
|
||||
* @api
|
||||
* @param Sheet $sheet The sheet to set as current
|
||||
* @return void
|
||||
* @throws WriterNotOpenedException If the writer has not been opened yet
|
||||
* @throws SheetNotFoundException If the given sheet does not exist in the workbook
|
||||
* @return void
|
||||
*/
|
||||
public function setCurrentSheet($sheet)
|
||||
{
|
||||
@@ -147,8 +148,8 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract
|
||||
/**
|
||||
* Checks if the workbook has been created. Throws an exception if not created yet.
|
||||
*
|
||||
* @return void
|
||||
* @throws WriterNotOpenedException If the workbook is not created yet
|
||||
* @return void
|
||||
*/
|
||||
protected function throwIfWorkbookIsNotAvailable()
|
||||
{
|
||||
@@ -165,9 +166,9 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract
|
||||
* @param array $dataRow Array containing data to be written.
|
||||
* Example $dataRow = ['data1', 1234, null, '', 'data5'];
|
||||
* @param \Box\Spout\Writer\Common\Entity\Style\Style $style Style to be applied to the row.
|
||||
* @return void
|
||||
* @throws WriterNotOpenedException If the book is not created yet
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to write data
|
||||
* @return void
|
||||
*/
|
||||
protected function addRowToWriter(array $dataRow, $style)
|
||||
{
|
||||
@@ -187,4 +188,3 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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