summaryrefslogtreecommitdiff
path: root/sheet.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2021-07-04 12:13:06 +0800
committerxuri <xuri.me@gmail.com>2021-07-04 12:13:06 +0800
commit0e02329bedf6648259fd219642bb907bdb07fd21 (patch)
tree16551d2174313dad46c3e276a6e27ffee5213bda /sheet.go
parent5ec61310dc55c9af93d66e6d225f721738416d1f (diff)
This closes #861, support concurrency get cell picture and remove unused internal function `getSheetNameByID`
Diffstat (limited to 'sheet.go')
-rw-r--r--sheet.go43
1 files changed, 15 insertions, 28 deletions
diff --git a/sheet.go b/sheet.go
index 555f8e3..420235c 100644
--- a/sheet.go
+++ b/sheet.go
@@ -231,15 +231,16 @@ func (f *File) setWorkbook(name string, sheetID, rid int) {
// relsWriter provides a function to save relationships after
// serialize structure.
func (f *File) relsWriter() {
- for path, rel := range f.Relationships {
+ f.Relationships.Range(func(path, rel interface{}) bool {
if rel != nil {
- output, _ := xml.Marshal(rel)
- if strings.HasPrefix(path, "xl/worksheets/sheet/rels/sheet") {
- output = f.replaceNameSpaceBytes(path, output)
+ output, _ := xml.Marshal(rel.(*xlsxRelationships))
+ if strings.HasPrefix(path.(string), "xl/worksheets/sheet/rels/sheet") {
+ output = f.replaceNameSpaceBytes(path.(string), output)
}
- f.saveFileList(path, replaceRelationshipsBytes(output))
+ f.saveFileList(path.(string), replaceRelationshipsBytes(output))
}
- }
+ return true
+ })
}
// setAppXML update docProps/app.xml file of XML.
@@ -359,22 +360,6 @@ func (f *File) SetSheetName(oldName, newName string) {
}
}
-// getSheetNameByID provides a function to get worksheet name of the
-// spreadsheet by given worksheet ID. If given sheet ID is invalid, will
-// return an empty string.
-func (f *File) getSheetNameByID(ID int) string {
- wb := f.workbookReader()
- if wb == nil || ID < 1 {
- return ""
- }
- for _, sheet := range wb.Sheets.Sheet {
- if ID == sheet.SheetID {
- return sheet.Name
- }
- }
- return ""
-}
-
// GetSheetName provides a function to get the sheet name of the workbook by
// the given sheet index. If the given sheet index is invalid, it will return
// an empty string.
@@ -541,7 +526,7 @@ func (f *File) DeleteSheet(name string) {
delete(f.sheetMap, sheetName)
delete(f.XLSX, sheetXML)
delete(f.XLSX, rels)
- delete(f.Relationships, rels)
+ f.Relationships.Delete(rels)
delete(f.Sheet, sheetXML)
delete(f.xmlAttr, sheetXML)
f.SheetCount--
@@ -1727,8 +1712,8 @@ func (f *File) RemovePageBreak(sheet, cell string) (err error) {
// after deserialization of xl/worksheets/_rels/sheet%d.xml.rels.
func (f *File) relsReader(path string) *xlsxRelationships {
var err error
-
- if f.Relationships[path] == nil {
+ rels, _ := f.Relationships.Load(path)
+ if rels == nil {
_, ok := f.XLSX[path]
if ok {
c := xlsxRelationships{}
@@ -1736,11 +1721,13 @@ func (f *File) relsReader(path string) *xlsxRelationships {
Decode(&c); err != nil && err != io.EOF {
log.Printf("xml decode error: %s", err)
}
- f.Relationships[path] = &c
+ f.Relationships.Store(path, &c)
}
}
-
- return f.Relationships[path]
+ if rels, _ = f.Relationships.Load(path); rels != nil {
+ return rels.(*xlsxRelationships)
+ }
+ return nil
}
// fillSheetData ensures there are enough rows, and columns in the chosen