| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\OpenSpout\Writer\XLSX\Manager; |
| 4 |
|
| 5 |
use FluentCart\OpenSpout\Writer\Common\Entity\Sheet; |
| 6 |
use FluentCart\OpenSpout\Writer\Common\Manager\WorkbookManagerAbstract; |
| 7 |
use FluentCart\OpenSpout\Writer\XLSX\Helper\FileSystemHelper; |
| 8 |
use FluentCart\OpenSpout\Writer\XLSX\Manager\Style\StyleManager; |
| 9 |
/** |
| 10 |
* XLSX workbook manager, providing the interfaces to work with workbook. |
| 11 |
*/ |
| 12 |
class WorkbookManager extends WorkbookManagerAbstract |
| 13 |
{ |
| 14 |
/** |
| 15 |
* Maximum number of rows a XLSX sheet can contain. |
| 16 |
* |
| 17 |
* @see http://office.microsoft.com/en-us/excel-help/excel-specifications-and-limits-HP010073849.aspx |
| 18 |
*/ |
| 19 |
protected static $maxRowsPerWorksheet = 1048576; |
| 20 |
/** @var WorksheetManager Object used to manage worksheets */ |
| 21 |
protected $worksheetManager; |
| 22 |
/** @var StyleManager Manages styles */ |
| 23 |
protected $styleManager; |
| 24 |
/** @var FileSystemHelper Helper to perform file system operations */ |
| 25 |
protected $fileSystemHelper; |
| 26 |
/** |
| 27 |
* @return string The file path where the data for the given sheet will be stored |
| 28 |
*/ |
| 29 |
public function getWorksheetFilePath(Sheet $sheet) |
| 30 |
{ |
| 31 |
$worksheetFilesFolder = $this->fileSystemHelper->getXlWorksheetsFolder(); |
| 32 |
return $worksheetFilesFolder . '/' . \strtolower($sheet->getName()) . '.xml'; |
| 33 |
} |
| 34 |
/** |
| 35 |
* @return int Maximum number of rows/columns a sheet can contain |
| 36 |
*/ |
| 37 |
protected function getMaxRowsPerWorksheet() |
| 38 |
{ |
| 39 |
return self::$maxRowsPerWorksheet; |
| 40 |
} |
| 41 |
/** |
| 42 |
* Closes custom objects that are still opened. |
| 43 |
*/ |
| 44 |
protected function closeRemainingObjects() |
| 45 |
{ |
| 46 |
$this->worksheetManager->getSharedStringsManager()->close(); |
| 47 |
} |
| 48 |
/** |
| 49 |
* Writes all the necessary files to disk and zip them together to create the final file. |
| 50 |
* |
| 51 |
* @param resource $finalFilePointer Pointer to the spreadsheet that will be created |
| 52 |
*/ |
| 53 |
protected function writeAllFilesToDiskAndZipThem($finalFilePointer) |
| 54 |
{ |
| 55 |
$worksheets = $this->getWorksheets(); |
| 56 |
$this->fileSystemHelper->createContentTypesFile($worksheets)->createWorkbookFile($worksheets)->createWorkbookRelsFile($worksheets)->createStylesFile($this->styleManager)->zipRootFolderAndCopyToStream($finalFilePointer); |
| 57 |
} |
| 58 |
} |
| 59 |
|