1 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace OpenSpout\Writer\XLSX\Manager;
|
|
|
6 |
|
|
|
7 |
use OpenSpout\Writer\Common\Entity\Workbook;
|
|
|
8 |
use OpenSpout\Writer\Common\Manager\AbstractWorkbookManager;
|
|
|
9 |
use OpenSpout\Writer\Common\Manager\Style\StyleMerger;
|
|
|
10 |
use OpenSpout\Writer\XLSX\Helper\FileSystemHelper;
|
|
|
11 |
use OpenSpout\Writer\XLSX\Manager\Style\StyleManager;
|
|
|
12 |
use OpenSpout\Writer\XLSX\Options;
|
|
|
13 |
|
|
|
14 |
/**
|
|
|
15 |
* @internal
|
|
|
16 |
*
|
|
|
17 |
* @property WorksheetManager $worksheetManager
|
|
|
18 |
* @property StyleManager $styleManager
|
|
|
19 |
* @property FileSystemHelper $fileSystemHelper
|
|
|
20 |
* @property Options $options
|
|
|
21 |
*/
|
|
|
22 |
final class WorkbookManager extends AbstractWorkbookManager
|
|
|
23 |
{
|
|
|
24 |
/**
|
|
|
25 |
* Maximum number of rows a XLSX sheet can contain.
|
|
|
26 |
*
|
|
|
27 |
* @see http://office.microsoft.com/en-us/excel-help/excel-specifications-and-limits-HP010073849.aspx
|
|
|
28 |
*/
|
|
|
29 |
private static int $maxRowsPerWorksheet = 1048576;
|
|
|
30 |
|
|
|
31 |
public function __construct(
|
|
|
32 |
Workbook $workbook,
|
|
|
33 |
Options $options,
|
|
|
34 |
WorksheetManager $worksheetManager,
|
|
|
35 |
StyleManager $styleManager,
|
|
|
36 |
StyleMerger $styleMerger,
|
|
|
37 |
FileSystemHelper $fileSystemHelper
|
|
|
38 |
) {
|
|
|
39 |
parent::__construct(
|
|
|
40 |
$workbook,
|
|
|
41 |
$options,
|
|
|
42 |
$worksheetManager,
|
|
|
43 |
$styleManager,
|
|
|
44 |
$styleMerger,
|
|
|
45 |
$fileSystemHelper
|
|
|
46 |
);
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* @return int Maximum number of rows/columns a sheet can contain
|
|
|
51 |
*/
|
|
|
52 |
protected function getMaxRowsPerWorksheet(): int
|
|
|
53 |
{
|
|
|
54 |
return self::$maxRowsPerWorksheet;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* Closes custom objects that are still opened.
|
|
|
59 |
*/
|
|
|
60 |
protected function closeRemainingObjects(): void
|
|
|
61 |
{
|
|
|
62 |
$this->worksheetManager->getSharedStringsManager()->close();
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
* Writes all the necessary files to disk and zip them together to create the final file.
|
|
|
67 |
*
|
|
|
68 |
* @param resource $finalFilePointer Pointer to the spreadsheet that will be created
|
|
|
69 |
*/
|
|
|
70 |
protected function writeAllFilesToDiskAndZipThem($finalFilePointer): void
|
|
|
71 |
{
|
|
|
72 |
$worksheets = $this->getWorksheets();
|
|
|
73 |
|
|
|
74 |
$this->fileSystemHelper
|
|
|
75 |
->createContentFiles($this->options, $worksheets)
|
|
|
76 |
->deleteWorksheetTempFolder()
|
|
|
77 |
->createContentTypesFile($worksheets)
|
|
|
78 |
->createWorkbookFile($worksheets)
|
|
|
79 |
->createWorkbookRelsFile($worksheets)
|
|
|
80 |
->createWorksheetRelsFiles($worksheets)
|
|
|
81 |
->createStylesFile($this->styleManager)
|
|
|
82 |
->zipRootFolderAndCopyToStream($finalFilePointer)
|
|
|
83 |
;
|
|
|
84 |
}
|
|
|
85 |
}
|