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