1 | <?php |
||
13 | class SheetManager |
||
14 | { |
||
15 | /** Paths of XML files relative to the XLSX file root */ |
||
16 | const WORKBOOK_XML_RELS_FILE_PATH = 'xl/_rels/workbook.xml.rels'; |
||
17 | const WORKBOOK_XML_FILE_PATH = 'xl/workbook.xml'; |
||
18 | |||
19 | /** Definition of XML node names used to parse data */ |
||
20 | const XML_NODE_WORKBOOK_PROPERTIES = 'workbookPr'; |
||
21 | const XML_NODE_WORKBOOK_VIEW = 'workbookView'; |
||
22 | const XML_NODE_SHEET = 'sheet'; |
||
23 | const XML_NODE_SHEETS = 'sheets'; |
||
24 | const XML_NODE_RELATIONSHIP = 'Relationship'; |
||
25 | |||
26 | /** Definition of XML attributes used to parse data */ |
||
27 | const XML_ATTRIBUTE_DATE_1904 = 'date1904'; |
||
28 | const XML_ATTRIBUTE_ACTIVE_TAB = 'activeTab'; |
||
29 | const XML_ATTRIBUTE_R_ID = 'r:id'; |
||
30 | const XML_ATTRIBUTE_NAME = 'name'; |
||
31 | const XML_ATTRIBUTE_ID = 'Id'; |
||
32 | const XML_ATTRIBUTE_TARGET = 'Target'; |
||
33 | |||
34 | /** @var string Path of the XLSX file being read */ |
||
35 | protected $filePath; |
||
36 | |||
37 | /** @var \Box\Spout\Common\Manager\OptionsManagerInterface Reader's options manager */ |
||
38 | protected $optionsManager; |
||
39 | |||
40 | /** @var \Box\Spout\Reader\XLSX\Manager\SharedStringsManager Manages shared strings */ |
||
41 | protected $sharedStringsManager; |
||
42 | |||
43 | /** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper Helper to work with global functions */ |
||
44 | protected $globalFunctionsHelper; |
||
45 | |||
46 | /** @var EntityFactory Factory to create entities */ |
||
47 | protected $entityFactory; |
||
48 | |||
49 | /** @var \Box\Spout\Common\Helper\Escaper\XLSX Used to unescape XML data */ |
||
50 | protected $escaper; |
||
51 | |||
52 | /** |
||
53 | * @param string $filePath Path of the XLSX file being read |
||
54 | * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager |
||
55 | * @param \Box\Spout\Reader\XLSX\Manager\SharedStringsManager $sharedStringsManager Manages shared strings |
||
56 | * @param \Box\Spout\Common\Helper\Escaper\XLSX $escaper Used to unescape XML data |
||
57 | * @param EntityFactory $entityFactory Factory to create entities |
||
58 | * @param mixed $sharedStringsManager |
||
59 | */ |
||
60 | 35 | public function __construct($filePath, $optionsManager, $sharedStringsManager, $escaper, $entityFactory) |
|
68 | |||
69 | /** |
||
70 | * Returns the sheets metadata of the file located at the previously given file path. |
||
71 | * The paths to the sheets' data are read from the [Content_Types].xml file. |
||
72 | * |
||
73 | * @return Sheet[] Sheets within the XLSX file |
||
74 | */ |
||
75 | 35 | public function getSheets() |
|
107 | |||
108 | /** |
||
109 | * Returns an instance of a sheet, given the XML node describing the sheet - from "workbook.xml". |
||
110 | * We can find the XML file path describing the sheet inside "workbook.xml.res", by mapping with the sheet ID |
||
111 | * ("r:id" in "workbook.xml", "Id" in "workbook.xml.res"). |
||
112 | * |
||
113 | * @param \Box\Spout\Reader\Wrapper\XMLReader $xmlReaderOnSheetNode XML Reader instance, pointing on the node describing the sheet, as defined in "workbook.xml" |
||
114 | * @param int $sheetIndexZeroBased Index of the sheet, based on order of appearance in the workbook (zero-based) |
||
115 | * @param bool $isSheetActive Whether this sheet was defined as active |
||
116 | * @return \Box\Spout\Reader\XLSX\Sheet Sheet instance |
||
117 | */ |
||
118 | 34 | protected function getSheetFromSheetXMLNode($xmlReaderOnSheetNode, $sheetIndexZeroBased, $isSheetActive) |
|
136 | |||
137 | /** |
||
138 | * @param string $sheetId The sheet ID, as defined in "workbook.xml" |
||
139 | * @return string The XML file path describing the sheet inside "workbook.xml.res", for the given sheet ID |
||
140 | */ |
||
141 | 34 | protected function getSheetDataXMLFilePathForSheetId($sheetId) |
|
171 | } |
||
172 |