|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Box\Spout\Writer\XLSX\Manager; |
|
4
|
|
|
|
|
5
|
|
|
use Box\Spout\Writer\Common\Sheet; |
|
6
|
|
|
use Box\Spout\Writer\Manager\WorkbookManagerAbstract; |
|
7
|
|
|
use Box\Spout\Writer\XLSX\Helper\FileSystemHelper; |
|
8
|
|
|
use Box\Spout\Writer\XLSX\Helper\StyleHelper; |
|
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 FileSystemHelper Helper to perform file system operations */ |
|
28
|
|
|
protected $fileSystemHelper; |
|
29
|
|
|
|
|
30
|
|
|
/** @var StyleHelper Helper to apply styles */ |
|
31
|
|
|
protected $styleHelper; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @return int Maximum number of rows/columns a sheet can contain |
|
35
|
|
|
*/ |
|
36
|
33 |
|
protected function getMaxRowsPerWorksheet() |
|
37
|
|
|
{ |
|
38
|
33 |
|
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
|
46 |
|
public function getWorksheetFilePath(Sheet $sheet) |
|
46
|
|
|
{ |
|
47
|
46 |
|
$worksheetFilesFolder = $this->fileSystemHelper->getXlWorksheetsFolder(); |
|
48
|
46 |
|
return $worksheetFilesFolder . '/' . strtolower($sheet->getName()) . '.xml'; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Closes custom objects that are still opened |
|
53
|
|
|
* |
|
54
|
|
|
* @return void |
|
55
|
|
|
*/ |
|
56
|
36 |
|
protected function closeRemainingObjects() |
|
57
|
|
|
{ |
|
58
|
36 |
|
$this->worksheetManager->getSharedStringsHelper()->close(); |
|
59
|
36 |
|
} |
|
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
|
36 |
|
protected function writeAllFilesToDiskAndZipThem($finalFilePointer) |
|
68
|
|
|
{ |
|
69
|
36 |
|
$worksheets = $this->getWorksheets(); |
|
70
|
|
|
|
|
71
|
36 |
|
$this->fileSystemHelper |
|
72
|
36 |
|
->createContentTypesFile($worksheets) |
|
73
|
36 |
|
->createWorkbookFile($worksheets) |
|
74
|
36 |
|
->createWorkbookRelsFile($worksheets) |
|
75
|
36 |
|
->createStylesFile($this->styleHelper) |
|
76
|
36 |
|
->zipRootFolderAndCopyToStream($finalFilePointer); |
|
77
|
|
|
} |
|
78
|
|
|
} |