summaryrefslogtreecommitdiff
path: root/sheet.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2021-02-11 00:07:46 +0800
committerxuri <xuri.me@gmail.com>2021-02-11 10:54:38 +0800
commit3648335d7f45d5cf204c32345f47e8938fe86bfb (patch)
tree19d431963317f82f78b063b0a90644c3f370718c /sheet.go
parent3783d1d01b458a56a4de6aba4a2d10605bfbc876 (diff)
This improves compatibility for worksheet relative XML path and multi rules auto filter
Diffstat (limited to 'sheet.go')
-rw-r--r--sheet.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/sheet.go b/sheet.go
index 0d6f5d1..b0e2971 100644
--- a/sheet.go
+++ b/sheet.go
@@ -447,17 +447,17 @@ func (f *File) GetSheetList() (list []string) {
// getSheetMap provides a function to get worksheet name and XML file path map
// of the spreadsheet.
func (f *File) getSheetMap() map[string]string {
- content := f.workbookReader()
- rels := f.relsReader(f.getWorkbookRelsPath())
maps := map[string]string{}
- for _, v := range content.Sheets.Sheet {
- for _, rel := range rels.Relationships {
+ for _, v := range f.workbookReader().Sheets.Sheet {
+ for _, rel := range f.relsReader(f.getWorkbookRelsPath()).Relationships {
if rel.ID == v.ID {
- // Construct a target XML as xl/worksheets/sheet%d by split path, compatible with different types of relative paths in workbook.xml.rels, for example: worksheets/sheet%d.xml and /xl/worksheets/sheet%d.xml
- pathInfo := strings.Split(rel.Target, "/")
- pathInfoLen := len(pathInfo)
- if pathInfoLen > 1 {
- maps[v.Name] = fmt.Sprintf("xl/%s", strings.Join(pathInfo[pathInfoLen-2:], "/"))
+ // Construct a target XML as xl/worksheets/sheet%d by split
+ // path, compatible with different types of relative paths in
+ // workbook.xml.rels, for example: worksheets/sheet%d.xml
+ // and /xl/worksheets/sheet%d.xml
+ path := filepath.ToSlash(strings.TrimPrefix(filepath.Clean(fmt.Sprintf("%s/%s", filepath.Dir(f.getWorkbookPath()), rel.Target)), "/"))
+ if _, ok := f.XLSX[path]; ok {
+ maps[v.Name] = path
}
}
}