Ver código fonte

Handle special shared string table file name `xl/SharedStrings.xml`, relate issue #188

Ri Xu 7 anos atrás
pai
commit
b1b056e0eb
3 arquivos alterados com 14 adições e 1 exclusões
  1. 9 0
      excelize_test.go
  2. 5 1
      rows.go
  3. BIN
      test/SharedStrings.xlsx

+ 9 - 0
excelize_test.go

@@ -1009,3 +1009,12 @@ func TestTitleToNumber(t *testing.T) {
 		t.Error("Conver title to number failed")
 	}
 }
+
+func TestSharedStrings(t *testing.T) {
+	xlsx, err := OpenFile("./test/SharedStrings.xlsx")
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	xlsx.GetRows("Sheet1")
+}

+ 5 - 1
rows.go

@@ -149,7 +149,11 @@ func (f *File) GetRowHeight(sheet string, row int) float64 {
 func (f *File) sharedStringsReader() *xlsxSST {
 	if f.SharedStrings == nil {
 		var sharedStrings xlsxSST
-		xml.Unmarshal([]byte(f.readXML("xl/sharedStrings.xml")), &sharedStrings)
+		ss := f.readXML("xl/sharedStrings.xml")
+		if ss == "" {
+			ss = f.readXML("xl/SharedStrings.xml")
+		}
+		xml.Unmarshal([]byte(ss), &sharedStrings)
 		f.SharedStrings = &sharedStrings
 	}
 	return f.SharedStrings

BIN
test/SharedStrings.xlsx