fileSystemHelper = new FileSystemHelper($tempFolder); $this->fileSystemHelper->createBaseFilesAndFolders(); $this->styleHelper = new StyleHelper($defaultRowStyle); } /** * @return \Box\Spout\Writer\ODS\Helper\StyleHelper Helper to apply styles to ODS files */ protected function getStyleHelper() { return $this->styleHelper; } /** * @return int Maximum number of rows/columns a sheet can contain */ protected function getMaxRowsPerWorksheet() { return self::$maxRowsPerWorksheet; } /** * 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 */ public function addNewSheet() { $newSheetIndex = count($this->worksheets); $sheet = new Sheet($newSheetIndex); $sheetsContentTempFolder = $this->fileSystemHelper->getSheetsContentTempFolder(); $worksheet = new Worksheet($sheet, $sheetsContentTempFolder); $this->worksheets[] = $worksheet; return $worksheet; } /** * Closes the workbook and all its associated sheets. * All the necessary files are written to disk and zipped together to create the ODS file. * All the temporary files are then deleted. * * @param resource $finalFilePointer Pointer to the ODS that will be created * @return void */ public function close($finalFilePointer) { /** @var Worksheet[] $worksheets */ $worksheets = $this->worksheets; $numWorksheets = count($worksheets); foreach ($worksheets as $worksheet) { $worksheet->close(); } // Finish creating all the necessary files before zipping everything together $this->fileSystemHelper ->createContentFile($worksheets, $this->styleHelper) ->deleteWorksheetTempFolder() ->createStylesFile($this->styleHelper, $numWorksheets) ->zipRootFolderAndCopyToStream($finalFilePointer); $this->cleanupTempFolder(); } /** * Deletes the root folder created in the temp folder and all its contents. * * @return void */ protected function cleanupTempFolder() { $xlsxRootFolder = $this->fileSystemHelper->getRootFolder(); $this->fileSystemHelper->deleteFolderRecursively($xlsxRootFolder); } }