From b1b056e0ebe0f05bae16023bf4972bda226de40c Mon Sep 17 00:00:00 2001 From: Ri Xu Date: Fri, 2 Mar 2018 10:19:40 +0800 Subject: Handle special shared string table file name `xl/SharedStrings.xml`, relate issue #188 --- excelize_test.go | 9 +++++++++ rows.go | 6 +++++- test/SharedStrings.xlsx | Bin 0 -> 6462 bytes 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100755 test/SharedStrings.xlsx diff --git a/excelize_test.go b/excelize_test.go index ca705e5..0d0fdf1 100644 --- a/excelize_test.go +++ b/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") +} diff --git a/rows.go b/rows.go index a6b0738..405717c 100644 --- a/rows.go +++ b/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 diff --git a/test/SharedStrings.xlsx b/test/SharedStrings.xlsx new file mode 100755 index 0000000..7b722d9 Binary files /dev/null and b/test/SharedStrings.xlsx differ -- cgit v1.2.1