speedup get cell value from shared string table

formula
xuri 5 years ago
parent 5c99300ee4
commit c168233e70
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7

@ -299,14 +299,13 @@ func (f *File) setCellString(value string) (t string, v string, ns xml.Attr) {
// setSharedString provides a function to add string to the share string table. // setSharedString provides a function to add string to the share string table.
func (f *File) setSharedString(val string) int { func (f *File) setSharedString(val string) int {
sst := f.sharedStringsReader() sst := f.sharedStringsReader()
for i, si := range sst.SI { if i, ok := f.sharedStringsMap[val]; ok {
if si.T == val { return i
return i
}
} }
sst.Count++ sst.Count++
sst.UniqueCount++ sst.UniqueCount++
sst.SI = append(sst.SI, xlsxSI{T: val}) sst.SI = append(sst.SI, xlsxSI{T: val})
f.sharedStringsMap[val] = sst.UniqueCount - 1
return sst.UniqueCount - 1 return sst.UniqueCount - 1
} }

@ -38,6 +38,7 @@ type File struct {
Drawings map[string]*xlsxWsDr Drawings map[string]*xlsxWsDr
Path string Path string
SharedStrings *xlsxSST SharedStrings *xlsxSST
sharedStringsMap map[string]int
Sheet map[string]*xlsxWorksheet Sheet map[string]*xlsxWorksheet
SheetCount int SheetCount int
Styles *xlsxStyleSheet Styles *xlsxStyleSheet
@ -75,6 +76,7 @@ func newFile() *File {
sheetMap: make(map[string]string), sheetMap: make(map[string]string),
Comments: make(map[string]*xlsxComments), Comments: make(map[string]*xlsxComments),
Drawings: make(map[string]*xlsxWsDr), Drawings: make(map[string]*xlsxWsDr),
sharedStringsMap: make(map[string]int),
Sheet: make(map[string]*xlsxWorksheet), Sheet: make(map[string]*xlsxWorksheet),
DecodeVMLDrawing: make(map[string]*decodeVmlDrawing), DecodeVMLDrawing: make(map[string]*decodeVmlDrawing),
VMLDrawing: make(map[string]*vmlDrawing), VMLDrawing: make(map[string]*vmlDrawing),

@ -292,6 +292,11 @@ func (f *File) sharedStringsReader() *xlsxSST {
log.Printf("xml decode error: %s", err) log.Printf("xml decode error: %s", err)
} }
f.SharedStrings = &sharedStrings f.SharedStrings = &sharedStrings
for i := range sharedStrings.SI {
if sharedStrings.SI[i].T != "" {
f.sharedStringsMap[sharedStrings.SI[i].T] = i
}
}
f.addContentTypePart(0, "sharedStrings") f.addContentTypePart(0, "sharedStrings")
rels := f.relsReader("xl/_rels/workbook.xml.rels") rels := f.relsReader("xl/_rels/workbook.xml.rels")
for _, rel := range rels.Relationships { for _, rel := range rels.Relationships {

Loading…
Cancel
Save