@@ -132,40 +132,6 @@ private function loadZip(string $filename, string $ns = ''): SimpleXMLElement
132
132
return self ::testSimpleXml ($ rels );
133
133
}
134
134
135
- private function loadStyleZip (string $ filename , string $ ns = '' ): SimpleXMLElement
136
- {
137
- // With the following:
138
- // <x:styleSheet xmlns:x="whatever"...
139
- // simplexml_load_file specifying namespace works fine,
140
- // but xpath on the result does not. I can't figure out
141
- // how to make xpath work in this circumstance, but I can
142
- // manipulate the xml to the far more usual:
143
- // <stylesheet xmlns="whatever"...
144
- // Ugly, but arguably serviceable.
145
- $ xml = $ this ->getFromZipArchive ($ this ->zip , $ filename );
146
- $ xmlns = " xmlns= \"$ ns \"" ;
147
- if (strpos ($ xml , $ xmlns ) === false ) {
148
- $ pattern = "~ xmlns:([A-Za-z0-9_]+)= \"$ ns \"~ " ;
149
- if (preg_match ($ pattern , $ xml , $ matches ) === 1 ) {
150
- $ pattern = "~ xmlns: $ {matches[1 ]}=~ " ;
151
- $ repl = Worksheet::pregReplace ($ pattern , ' xmlns= ' , $ xml );
152
- $ pattern = "~<(/?) $ {matches[1 ]}:~ " ;
153
- $ repl = Worksheet::pregReplace ($ pattern , '<$1 ' , $ repl );
154
- if ($ repl !== '' ) {
155
- $ xml = $ repl ;
156
- }
157
- }
158
- }
159
- $ rels = simplexml_load_string (
160
- $ this ->securityScanner ->scan ($ xml ),
161
- 'SimpleXMLElement ' ,
162
- 0 ,
163
- $ ns
164
- );
165
-
166
- return self ::testSimpleXml ($ rels );
167
- }
168
-
169
135
// This function is just to identify cases where I'm not sure
170
136
// why empty namespace is required.
171
137
private function loadZipNonamespace (string $ filename , string $ ns ): SimpleXMLElement
@@ -572,15 +538,31 @@ public function load(string $filename, int $flags = 0): Spreadsheet
572
538
if ($ xpath === null ) {
573
539
$ xmlStyles = self ::testSimpleXml (null );
574
540
} else {
575
- $ xmlStyles = $ this ->loadStyleZip ("$ dir/ $ xpath [Target]" , $ mainNS );
541
+ $ xmlStyles = $ this ->loadZip ("$ dir/ $ xpath [Target]" , $ mainNS );
576
542
}
577
543
578
- $ xmlStyles ->registerXPathNamespace ('smm ' , $ mainNS );
579
- $ fills = self ::xpathNoFalse ($ xmlStyles , 'smm:fills/smm:fill ' );
580
- $ fonts = self ::xpathNoFalse ($ xmlStyles , 'smm:fonts/smm:font ' );
581
- $ borders = self ::xpathNoFalse ($ xmlStyles , 'smm:borders/smm:border ' );
582
- $ xfTags = self ::xpathNoFalse ($ xmlStyles , 'smm:cellXfs/smm:xf ' );
583
- $ cellXfTags = self ::xpathNoFalse ($ xmlStyles , 'smm:cellStyleXfs/smm:xf ' );
544
+ $ fills = [];
545
+ $ fonts = [];
546
+ $ borders = [];
547
+ $ xfTags = [];
548
+ $ cellXfTags = [];
549
+ if (count ($ xmlStyles ) > 0 ) {
550
+ foreach ($ xmlStyles ->fills ->fill as $ fill ) {
551
+ $ fills [] = $ fill ;
552
+ }
553
+ foreach ($ xmlStyles ->fonts ->font as $ font ) {
554
+ $ fonts [] = $ font ;
555
+ }
556
+ foreach ($ xmlStyles ->borders ->border as $ border ) {
557
+ $ borders [] = $ border ;
558
+ }
559
+ foreach ($ xmlStyles ->cellXfs ->xf as $ xf ) {
560
+ $ xfTags [] = $ xf ;
561
+ }
562
+ foreach ($ xmlStyles ->cellStyleXfs ->xf as $ xf ) {
563
+ $ cellXfTags [] = $ xf ;
564
+ }
565
+ }
584
566
585
567
$ styles = [];
586
568
$ cellStyles = [];
0 commit comments