Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 39 and 311]

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