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
|
32 |
|
protected function getMaxRowsPerWorksheet() |
35
|
|
|
{ |
36
|
32 |
|
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
|
40 |
|
public function getWorksheetFilePath(Sheet $sheet) |
44
|
|
|
{ |
45
|
40 |
|
$worksheetFilesFolder = $this->fileSystemHelper->getXlWorksheetsFolder(); |
46
|
|
|
|
47
|
40 |
|
return $worksheetFilesFolder . '/' . strtolower($sheet->getName()) . '.xml'; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Closes custom objects that are still opened |
52
|
|
|
* |
53
|
|
|
* @return void |
54
|
|
|
*/ |
55
|
36 |
|
protected function closeRemainingObjects() |
56
|
|
|
{ |
57
|
36 |
|
$this->worksheetManager->getSharedStringsManager()->close(); |
58
|
36 |
|
} |
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
|
36 |
|
protected function writeAllFilesToDiskAndZipThem($finalFilePointer) |
67
|
|
|
{ |
68
|
36 |
|
$worksheets = $this->getWorksheets(); |
69
|
|
|
|
70
|
36 |
|
$this->fileSystemHelper |
71
|
36 |
|
->createContentTypesFile($worksheets) |
72
|
36 |
|
->createWorkbookFile($worksheets) |
73
|
36 |
|
->createWorkbookRelsFile($worksheets) |
74
|
36 |
|
->createStylesFile($this->styleManager) |
75
|
36 |
|
->zipRootFolderAndCopyToStream($finalFilePointer); |
76
|
36 |
|
} |
77
|
|
|
} |
78
|
|
|
|