1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Akeneo\Component\SpreadsheetParser\Xlsx; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Entry point for XLSX reader |
7
|
|
|
* |
8
|
|
|
* @author Antoine Guigan <[email protected]> |
9
|
|
|
* @copyright 2014 Akeneo SAS (http://www.akeneo.com) |
10
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
11
|
|
|
*/ |
12
|
|
|
class XlsxParser |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @staticvar string the name of the format |
16
|
|
|
*/ |
17
|
|
|
const FORMAT_NAME = 'xlsx'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @staticvar string the name of the macro format |
21
|
|
|
*/ |
22
|
|
|
const MACRO_FORMAT_NAME = 'xlsm'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @staticvar string Archive class |
26
|
|
|
*/ |
27
|
|
|
const ARCHIVE_CLASS = 'Akeneo\Component\SpreadsheetParser\Xlsx\Archive'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @staticvar string Relationships class |
31
|
|
|
*/ |
32
|
|
|
const RELATIONSHIPS_CLASS = 'Akeneo\Component\SpreadsheetParser\Xlsx\Relationships'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @staticvar string RowBuilder class |
36
|
|
|
*/ |
37
|
|
|
const ROW_BUILDER_CLASS = 'Akeneo\Component\SpreadsheetParser\Xlsx\RowBuilder'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @staticvar string RowIterator class |
41
|
|
|
*/ |
42
|
|
|
const ROW_ITERATOR_CLASS = 'Akeneo\Component\SpreadsheetParser\Xlsx\RowIterator'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @staticvar string SharedStrings class |
46
|
|
|
*/ |
47
|
|
|
const SHARED_STRINGS_CLASS = 'Akeneo\Component\SpreadsheetParser\Xlsx\SharedStrings'; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @staticvar string Styles class |
51
|
|
|
*/ |
52
|
|
|
const STYLES_CLASS = 'Akeneo\Component\SpreadsheetParser\Xlsx\Styles'; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @staticvar string ValueTransformer class |
56
|
|
|
*/ |
57
|
|
|
const VALUE_TRANSFORMER_CLASS = 'Akeneo\Component\SpreadsheetParser\Xlsx\ValueTransformer'; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @staticvar string Spreadsheet class |
61
|
|
|
*/ |
62
|
|
|
const WORKBOOK_CLASS = 'Akeneo\Component\SpreadsheetParser\Xlsx\Spreadsheet'; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var SpreadsheetLoader |
66
|
|
|
*/ |
67
|
|
|
private static $spreadsheetLoader; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Opens an XLSX file |
71
|
|
|
* |
72
|
|
|
* @param string $path |
73
|
|
|
* |
74
|
|
|
* @return Spreadsheet |
75
|
|
|
*/ |
76
|
|
|
public static function open($path) |
77
|
|
|
{ |
78
|
|
|
return static::getSpreadsheetLoader()->open($path); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return SpreadsheetLoader |
83
|
|
|
*/ |
84
|
|
|
public static function getSpreadsheetLoader() |
85
|
|
|
{ |
86
|
|
|
if (!isset(self::$spreadsheetLoader)) { |
87
|
|
|
self::$spreadsheetLoader = new SpreadsheetLoader( |
88
|
|
|
static::createArchiveLoader(), |
89
|
|
|
static::createRelationshipsLoader(), |
90
|
|
|
static::createSharedStringsLoader(), |
91
|
|
|
static::createStylesLoader(), |
92
|
|
|
static::createWorksheetListReader(), |
93
|
|
|
static::createValueTransformerFactory(), |
94
|
|
|
static::createRowIteratorFactory(), |
95
|
|
|
static::WORKBOOK_CLASS |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return self::$spreadsheetLoader; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return ArchiveLoader |
104
|
|
|
*/ |
105
|
|
|
protected static function createArchiveLoader() |
106
|
|
|
{ |
107
|
|
|
return new ArchiveLoader(static::ARCHIVE_CLASS); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return RelationshipsLoader |
112
|
|
|
*/ |
113
|
|
|
protected static function createRelationshipsLoader() |
114
|
|
|
{ |
115
|
|
|
return new RelationshipsLoader(static::RELATIONSHIPS_CLASS); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return SharedStringsLoader |
120
|
|
|
*/ |
121
|
|
|
protected static function createSharedStringsLoader() |
122
|
|
|
{ |
123
|
|
|
return new SharedStringsLoader(static::SHARED_STRINGS_CLASS); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return StylesLoader |
128
|
|
|
*/ |
129
|
|
|
protected static function createStylesLoader() |
130
|
|
|
{ |
131
|
|
|
return new StylesLoader(static::STYLES_CLASS); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return WorksheetListReader |
136
|
|
|
*/ |
137
|
|
|
protected static function createWorksheetListReader() |
138
|
|
|
{ |
139
|
|
|
return new WorksheetListReader(); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return ValueTransformerFactory |
144
|
|
|
*/ |
145
|
|
|
protected static function createValueTransformerFactory() |
146
|
|
|
{ |
147
|
|
|
return new ValueTransformerFactory(static::createDateTransformer(), static::VALUE_TRANSFORMER_CLASS); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return DateTransformer |
152
|
|
|
*/ |
153
|
|
|
protected static function createDateTransformer() |
154
|
|
|
{ |
155
|
|
|
return new DateTransformer(); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @return RowBuilderFactory |
160
|
|
|
*/ |
161
|
|
|
protected static function createRowBuilderFactory() |
162
|
|
|
{ |
163
|
|
|
return new RowBuilderFactory(static::ROW_BUILDER_CLASS); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return ColumnIndexTransformer |
168
|
|
|
*/ |
169
|
|
|
protected static function createColumnIndexTransformer() |
170
|
|
|
{ |
171
|
|
|
return new ColumnIndexTransformer(); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @return RowIteratorFactory |
176
|
|
|
*/ |
177
|
|
|
protected static function createRowIteratorFactory() |
178
|
|
|
{ |
179
|
|
|
return new RowIteratorFactory( |
180
|
|
|
static::createRowBuilderFactory(), |
181
|
|
|
static::createColumnIndexTransformer(), |
182
|
|
|
static::ROW_ITERATOR_CLASS |
183
|
|
|
); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|