File tree Expand file tree Collapse file tree 1 file changed +10
-11
lines changed Expand file tree Collapse file tree 1 file changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -193,17 +193,7 @@ func readDataFromZIP(path string) ([]byte, error) {
193
193
}
194
194
defer r .Close ()
195
195
196
- var wfile * zip.File
197
- for _ , f := range r .File {
198
- if f .Name == workbookNameXLS {
199
- wfile = f
200
- break
201
- }
202
- if f .Name == workbookNameXLSX {
203
- wfile = f
204
- break
205
- }
206
- }
196
+ wfile := scanForWorkbook (r .File )
207
197
if wfile == nil {
208
198
return nil , fmt .Errorf (
209
199
"no file named %q or %q found in zip archive" ,
@@ -225,6 +215,15 @@ func readDataFromZIP(path string) ([]byte, error) {
225
215
return data , nil
226
216
}
227
217
218
+ func scanForWorkbook (files []* zip.File ) * zip.File {
219
+ for _ , f := range files {
220
+ if strings .HasSuffix (f .Name , workbookNameXLS ) || strings .HasSuffix (f .Name , workbookNameXLSX ) {
221
+ return f
222
+ }
223
+ }
224
+ return nil
225
+ }
226
+
228
227
func readDataFromXLSX (path string ) ([]byte , error ) {
229
228
return ioutil .ReadFile (path )
230
229
}
You can’t perform that action at this time.
0 commit comments