diff options
author | Alex Geer <monoflash@gmail.com> | 2019-12-19 19:30:48 +0300 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2019-12-20 00:30:48 +0800 |
commit | b1b3c0d15158abc71267da5893de020f047c3872 (patch) | |
tree | 53f9e5a1f42130825572a3c3eea39b2eb4d00f62 /rows.go | |
parent | a00ba75f0f294ce04bfe8d25703d13cd27d6284f (diff) |
Fix #539 Fixed error opening excel file created in encoding d… (#540)
* Fixed issue #539 Fixed error opening excel file created in encoding different from UTF-8, added logging of possible errors when decoding XML if the function does not provide exit with an error
* Added test for CharsetReader
* Fixed #discussion_r359397878
Discussion: https://github.com/360EntSecGroup-Skylar/excelize/pull/540#discussion_r359397878
* Fixed go fmt
* go mod tidy and removed unused imports
* The code has been refactored
Diffstat (limited to 'rows.go')
-rw-r--r-- | rows.go | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -10,9 +10,11 @@ package excelize import ( - "encoding/xml" + "bytes" "errors" "fmt" + "io" + "log" "math" "strconv" ) @@ -187,15 +189,21 @@ func (f *File) GetRowHeight(sheet string, row int) (float64, error) { // sharedStringsReader provides a function to get the pointer to the structure // after deserialization of xl/sharedStrings.xml. func (f *File) sharedStringsReader() *xlsxSST { + var err error + if f.SharedStrings == nil { var sharedStrings xlsxSST ss := f.readXML("xl/sharedStrings.xml") if len(ss) == 0 { ss = f.readXML("xl/SharedStrings.xml") } - _ = xml.Unmarshal(namespaceStrictToTransitional(ss), &sharedStrings) + if err = f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(ss))). + Decode(&sharedStrings); err != nil && err != io.EOF { + log.Printf("xml decode error: %s", err) + } f.SharedStrings = &sharedStrings } + return f.SharedStrings } |