|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Box\Spout\Reader\XLSX\Creator; |
|
4
|
|
|
|
|
5
|
|
|
use Box\Spout\Common\Entity\Cell; |
|
6
|
|
|
use Box\Spout\Common\Entity\Row; |
|
7
|
|
|
use Box\Spout\Reader\Common\Creator\InternalEntityFactoryInterface; |
|
8
|
|
|
use Box\Spout\Reader\Common\Entity\Options; |
|
9
|
|
|
use Box\Spout\Reader\Common\XMLProcessor; |
|
10
|
|
|
use Box\Spout\Reader\Wrapper\XMLReader; |
|
11
|
|
|
use Box\Spout\Reader\XLSX\Manager\SharedStringsManager; |
|
12
|
|
|
use Box\Spout\Reader\XLSX\RowIterator; |
|
13
|
|
|
use Box\Spout\Reader\XLSX\Sheet; |
|
14
|
|
|
use Box\Spout\Reader\XLSX\SheetIterator; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class InternalEntityFactory |
|
18
|
|
|
* Factory to create entities |
|
19
|
|
|
*/ |
|
20
|
|
|
class InternalEntityFactory implements InternalEntityFactoryInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var HelperFactory */ |
|
23
|
|
|
private $helperFactory; |
|
24
|
|
|
|
|
25
|
|
|
/** @var ManagerFactory */ |
|
26
|
|
|
private $managerFactory; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param ManagerFactory $managerFactory |
|
30
|
|
|
* @param HelperFactory $helperFactory |
|
31
|
|
|
*/ |
|
32
|
58 |
|
public function __construct(ManagerFactory $managerFactory, HelperFactory $helperFactory) |
|
33
|
|
|
{ |
|
34
|
58 |
|
$this->managerFactory = $managerFactory; |
|
35
|
58 |
|
$this->helperFactory = $helperFactory; |
|
36
|
58 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param string $filePath Path of the file to be read |
|
40
|
|
|
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager |
|
41
|
|
|
* @param SharedStringsManager $sharedStringsManager Manages shared strings |
|
42
|
|
|
* @return SheetIterator |
|
43
|
|
|
*/ |
|
44
|
39 |
|
public function createSheetIterator($filePath, $optionsManager, $sharedStringsManager) |
|
45
|
|
|
{ |
|
46
|
39 |
|
$sheetManager = $this->managerFactory->createSheetManager( |
|
47
|
39 |
|
$filePath, |
|
48
|
39 |
|
$optionsManager, |
|
49
|
39 |
|
$sharedStringsManager, |
|
50
|
39 |
|
$this |
|
51
|
|
|
); |
|
52
|
|
|
|
|
53
|
39 |
|
return new SheetIterator($sheetManager); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param string $filePath Path of the XLSX file being read |
|
58
|
|
|
* @param string $sheetDataXMLFilePath Path of the sheet data XML file as in [Content_Types].xml |
|
59
|
|
|
* @param int $sheetIndex Index of the sheet, based on order in the workbook (zero-based) |
|
60
|
|
|
* @param string $sheetName Name of the sheet |
|
61
|
|
|
* @param bool $isSheetActive Whether the sheet was defined as active |
|
62
|
|
|
* @param bool $isSheetVisible Whether the sheet is visible |
|
63
|
|
|
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager |
|
64
|
|
|
* @param SharedStringsManager $sharedStringsManager Manages shared strings |
|
65
|
|
|
* @return Sheet |
|
66
|
|
|
*/ |
|
67
|
38 |
|
public function createSheet( |
|
68
|
|
|
$filePath, |
|
69
|
|
|
$sheetDataXMLFilePath, |
|
70
|
|
|
$sheetIndex, |
|
71
|
|
|
$sheetName, |
|
72
|
|
|
$isSheetActive, |
|
73
|
|
|
$isSheetVisible, |
|
74
|
|
|
$optionsManager, |
|
75
|
|
|
$sharedStringsManager |
|
76
|
|
|
) { |
|
77
|
38 |
|
$rowIterator = $this->createRowIterator($filePath, $sheetDataXMLFilePath, $optionsManager, $sharedStringsManager); |
|
78
|
|
|
|
|
79
|
38 |
|
return new Sheet($rowIterator, $sheetIndex, $sheetName, $isSheetActive, $isSheetVisible); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param string $filePath Path of the XLSX file being read |
|
84
|
|
|
* @param string $sheetDataXMLFilePath Path of the sheet data XML file as in [Content_Types].xml |
|
85
|
|
|
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager |
|
86
|
|
|
* @param SharedStringsManager $sharedStringsManager Manages shared strings |
|
87
|
|
|
* @return RowIterator |
|
88
|
|
|
*/ |
|
89
|
38 |
|
private function createRowIterator($filePath, $sheetDataXMLFilePath, $optionsManager, $sharedStringsManager) |
|
90
|
|
|
{ |
|
91
|
38 |
|
$xmlReader = $this->createXMLReader(); |
|
92
|
38 |
|
$xmlProcessor = $this->createXMLProcessor($xmlReader); |
|
93
|
|
|
|
|
94
|
38 |
|
$styleManager = $this->managerFactory->createStyleManager($filePath, $this); |
|
95
|
38 |
|
$rowManager = $this->managerFactory->createRowManager($this); |
|
96
|
38 |
|
$shouldFormatDates = $optionsManager->getOption(Options::SHOULD_FORMAT_DATES); |
|
97
|
38 |
|
$shouldUse1904Dates = $optionsManager->getOption(Options::SHOULD_USE_1904_DATES); |
|
98
|
|
|
|
|
99
|
38 |
|
$cellValueFormatter = $this->helperFactory->createCellValueFormatter( |
|
100
|
38 |
|
$sharedStringsManager, |
|
101
|
38 |
|
$styleManager, |
|
102
|
38 |
|
$shouldFormatDates, |
|
103
|
38 |
|
$shouldUse1904Dates |
|
104
|
|
|
); |
|
105
|
|
|
|
|
106
|
38 |
|
$shouldPreserveEmptyRows = $optionsManager->getOption(Options::SHOULD_PRESERVE_EMPTY_ROWS); |
|
107
|
|
|
|
|
108
|
38 |
|
return new RowIterator( |
|
109
|
38 |
|
$filePath, |
|
110
|
38 |
|
$sheetDataXMLFilePath, |
|
111
|
38 |
|
$shouldPreserveEmptyRows, |
|
112
|
38 |
|
$xmlReader, |
|
113
|
38 |
|
$xmlProcessor, |
|
114
|
38 |
|
$cellValueFormatter, |
|
115
|
38 |
|
$rowManager, |
|
116
|
38 |
|
$this |
|
117
|
|
|
); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param Cell[] $cells |
|
122
|
|
|
* @return Row |
|
123
|
|
|
*/ |
|
124
|
35 |
|
public function createRow(array $cells = []) |
|
125
|
|
|
{ |
|
126
|
35 |
|
return new Row($cells, null); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @param mixed $cellValue |
|
131
|
|
|
* @return Cell |
|
132
|
|
|
*/ |
|
133
|
35 |
|
public function createCell($cellValue) |
|
134
|
|
|
{ |
|
135
|
35 |
|
return new Cell($cellValue); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @return \ZipArchive |
|
140
|
|
|
*/ |
|
141
|
41 |
|
public function createZipArchive() |
|
142
|
|
|
{ |
|
143
|
41 |
|
return new \ZipArchive(); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @return XMLReader |
|
148
|
|
|
*/ |
|
149
|
46 |
|
public function createXMLReader() |
|
150
|
|
|
{ |
|
151
|
46 |
|
return new XMLReader(); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @param $xmlReader |
|
156
|
|
|
* @return XMLProcessor |
|
157
|
|
|
*/ |
|
158
|
39 |
|
public function createXMLProcessor($xmlReader) |
|
159
|
|
|
{ |
|
160
|
39 |
|
return new XMLProcessor($xmlReader); |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|