|
|
@@ -7,6 +7,7 @@ import (
|
|
|
"fmt"
|
|
|
"io"
|
|
|
"math"
|
|
|
+ "path"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
)
|
|
|
@@ -630,11 +631,13 @@ func readSharedStringsFromZipFile(f *zip.File) ([]string, error) {
|
|
|
var decoder *xml.Decoder
|
|
|
var reftable []string
|
|
|
|
|
|
+
|
|
|
// In a file with no strings it's possible that
|
|
|
// sharedStrings.xml doesn't exist. In this case the value
|
|
|
// passed as f will be nil.
|
|
|
if f == nil {
|
|
|
- return make([]string,0), nil
|
|
|
+ reftable = make([]string, 0)
|
|
|
+ return reftable, nil
|
|
|
}
|
|
|
rc, error = f.Open()
|
|
|
if error != nil {
|
|
|
@@ -702,8 +705,9 @@ func readWorkbookRelationsFromZipFile(workbookRels *zip.File) (map[string]string
|
|
|
}
|
|
|
sheetXMLMap = make(map[string]string)
|
|
|
for _, rel := range wbRelationships.Relationships {
|
|
|
- if strings.HasSuffix(rel.Target, ".xml") && strings.HasPrefix(rel.Target, "worksheets/") {
|
|
|
- sheetXMLMap[rel.Id] = strings.Replace(rel.Target[len("worksheets/"):], ".xml", "", 1)
|
|
|
+ if strings.HasSuffix(rel.Target, ".xml") && rel.Type == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" {
|
|
|
+ _, filename := path.Split(rel.Target)
|
|
|
+ sheetXMLMap[rel.Id] = strings.Replace(filename, ".xml", "", 1)
|
|
|
}
|
|
|
}
|
|
|
return sheetXMLMap, nil
|
|
|
@@ -773,18 +777,15 @@ func ReadZipReader(r *zip.Reader) (*File, error) {
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
- if reftable == nil {
|
|
|
- readerErr := new(XLSXReaderError)
|
|
|
- readerErr.Err = "No valid sharedStrings.xml found in XLSX file"
|
|
|
- return nil, readerErr
|
|
|
- }
|
|
|
file.referenceTable = reftable
|
|
|
- style, err = readStylesFromZipFile(styles)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
+ if styles != nil {
|
|
|
+ style, err = readStylesFromZipFile(styles)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ file.styles = style
|
|
|
}
|
|
|
- file.styles = style
|
|
|
- file.numFmtRefTable = buildNumFmtRefTable(style)
|
|
|
sheets, err = readSheetsFromZipFile(workbook, file, sheetXMLMap)
|
|
|
if err != nil {
|
|
|
return nil, err
|