1 | <?php |
||
14 | class SheetManager |
||
15 | { |
||
16 | /** Paths of XML files relative to the XLSX file root */ |
||
17 | const WORKBOOK_XML_RELS_FILE_PATH = 'xl/_rels/workbook.xml.rels'; |
||
18 | const WORKBOOK_XML_FILE_PATH = 'xl/workbook.xml'; |
||
19 | |||
20 | /** Definition of XML node names used to parse data */ |
||
21 | const XML_NODE_WORKBOOK_PROPERTIES = 'workbookPr'; |
||
22 | const XML_NODE_WORKBOOK_VIEW = 'workbookView'; |
||
23 | const XML_NODE_SHEET = 'sheet'; |
||
24 | const XML_NODE_SHEETS = 'sheets'; |
||
25 | const XML_NODE_RELATIONSHIP = 'Relationship'; |
||
26 | |||
27 | /** Definition of XML attributes used to parse data */ |
||
28 | const XML_ATTRIBUTE_DATE_1904 = 'date1904'; |
||
29 | const XML_ATTRIBUTE_ACTIVE_TAB = 'activeTab'; |
||
30 | const XML_ATTRIBUTE_R_ID = 'r:id'; |
||
31 | const XML_ATTRIBUTE_NAME = 'name'; |
||
32 | const XML_ATTRIBUTE_ID = 'Id'; |
||
33 | const XML_ATTRIBUTE_TARGET = 'Target'; |
||
34 | |||
35 | /** @var string Path of the XLSX file being read */ |
||
36 | protected $filePath; |
||
37 | |||
38 | /** @var \Box\Spout\Common\Manager\OptionsManagerInterface Reader's options manager */ |
||
39 | protected $optionsManager; |
||
40 | |||
41 | /** @var \Box\Spout\Reader\XLSX\Manager\SharedStringsManager Manages shared strings */ |
||
42 | protected $sharedStringsManager; |
||
43 | |||
44 | /** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper Helper to work with global functions */ |
||
45 | protected $globalFunctionsHelper; |
||
46 | |||
47 | /** @var EntityFactory Factory to create entities */ |
||
48 | protected $entityFactory; |
||
49 | |||
50 | /** @var \Box\Spout\Common\Helper\Escaper\XLSX Used to unescape XML data */ |
||
51 | protected $escaper; |
||
52 | |||
53 | /** @var array List of sheets */ |
||
54 | protected $sheets; |
||
55 | |||
56 | /** @var int Index of the sheet currently read */ |
||
57 | protected $currentSheetIndex; |
||
58 | |||
59 | /** @var int Index of the active sheet (0 by default) */ |
||
60 | protected $activeSheetIndex; |
||
61 | |||
62 | /** |
||
63 | * @param string $filePath Path of the XLSX file being read |
||
64 | * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager |
||
65 | * @param \Box\Spout\Reader\XLSX\Manager\SharedStringsManager $sharedStringsManager Manages shared strings |
||
66 | * @param \Box\Spout\Common\Helper\Escaper\XLSX $escaper Used to unescape XML data |
||
67 | * @param EntityFactory $entityFactory Factory to create entities |
||
68 | * @param mixed $sharedStringsManager |
||
69 | */ |
||
70 | 35 | public function __construct($filePath, $optionsManager, $sharedStringsManager, $escaper, $entityFactory) |
|
78 | |||
79 | /** |
||
80 | * Returns the sheets metadata of the file located at the previously given file path. |
||
81 | * The paths to the sheets' data are read from the [Content_Types].xml file. |
||
82 | * |
||
83 | * @return Sheet[] Sheets within the XLSX file |
||
84 | */ |
||
85 | 35 | public function getSheets() |
|
106 | |||
107 | /** |
||
108 | * @param \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XMLReader object, positioned on a "<workbookPr>" starting node |
||
109 | * @return int A return code that indicates what action should the processor take next |
||
110 | */ |
||
111 | 12 | protected function processWorkbookPropertiesStartingNode($xmlReader) |
|
118 | |||
119 | /** |
||
120 | * @param \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XMLReader object, positioned on a "<workbookView>" starting node |
||
121 | * @return int A return code that indicates what action should the processor take next |
||
122 | */ |
||
123 | 13 | protected function processWorkbookViewStartingNode($xmlReader) |
|
131 | |||
132 | /** |
||
133 | * @param \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XMLReader object, positioned on a "<sheet>" starting node |
||
134 | * @return int A return code that indicates what action should the processor take next |
||
135 | */ |
||
136 | 34 | protected function processSheetStartingNode($xmlReader) |
|
144 | |||
145 | /** |
||
146 | * @return int A return code that indicates what action should the processor take next |
||
147 | */ |
||
148 | 35 | protected function processSheetsEndingNode() |
|
152 | |||
153 | /** |
||
154 | * Returns an instance of a sheet, given the XML node describing the sheet - from "workbook.xml". |
||
155 | * We can find the XML file path describing the sheet inside "workbook.xml.res", by mapping with the sheet ID |
||
156 | * ("r:id" in "workbook.xml", "Id" in "workbook.xml.res"). |
||
157 | * |
||
158 | * @param \Box\Spout\Reader\Wrapper\XMLReader $xmlReaderOnSheetNode XML Reader instance, pointing on the node describing the sheet, as defined in "workbook.xml" |
||
159 | * @param int $sheetIndexZeroBased Index of the sheet, based on order of appearance in the workbook (zero-based) |
||
160 | * @param bool $isSheetActive Whether this sheet was defined as active |
||
161 | * @return \Box\Spout\Reader\XLSX\Sheet Sheet instance |
||
162 | */ |
||
163 | 34 | protected function getSheetFromSheetXMLNode($xmlReaderOnSheetNode, $sheetIndexZeroBased, $isSheetActive) |
|
181 | |||
182 | /** |
||
183 | * @param string $sheetId The sheet ID, as defined in "workbook.xml" |
||
184 | * @return string The XML file path describing the sheet inside "workbook.xml.res", for the given sheet ID |
||
185 | */ |
||
186 | 34 | protected function getSheetDataXMLFilePathForSheetId($sheetId) |
|
216 | } |
||
217 |