From c82a185af83b8b3934efcb0b227e494a18f426ea Mon Sep 17 00:00:00 2001 From: xuri Date: Wed, 4 Nov 2020 00:28:20 +0800 Subject: Compatibility improvement: parse document core part (workbook) dynamically --- pivotTable.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'pivotTable.go') diff --git a/pivotTable.go b/pivotTable.go index b7c80c2..3a277c3 100644 --- a/pivotTable.go +++ b/pivotTable.go @@ -15,6 +15,7 @@ import ( "encoding/xml" "errors" "fmt" + "path/filepath" "strconv" "strings" ) @@ -138,7 +139,9 @@ func (f *File) AddPivotTable(opt *PivotTableOption) error { } // workbook pivot cache - workBookPivotCacheRID := f.addRels("xl/_rels/workbook.xml.rels", SourceRelationshipPivotCache, fmt.Sprintf("pivotCache/pivotCacheDefinition%d.xml", pivotCacheID), "") + wbPath := f.getWorkbookPath() + wbRelsPath := strings.TrimPrefix(filepath.Join(filepath.Dir(wbPath), "_rels", filepath.Base(wbPath)+".rels"), string(filepath.Separator)) + workBookPivotCacheRID := f.addRels(wbRelsPath, SourceRelationshipPivotCache, fmt.Sprintf("/xl/pivotCache/pivotCacheDefinition%d.xml", pivotCacheID), "") cacheID := f.addWorkbookPivotCache(workBookPivotCacheRID) pivotCacheRels := "xl/pivotTables/_rels/pivotTable" + strconv.Itoa(pivotTableID) + ".xml.rels" @@ -661,7 +664,7 @@ func (f *File) getPivotTableFieldNameDefaultSubtotal(name string, fields []Pivot return false, false } -// addWorkbookPivotCache add the association ID of the pivot cache in xl/workbook.xml. +// addWorkbookPivotCache add the association ID of the pivot cache in workbook.xml. func (f *File) addWorkbookPivotCache(RID int) int { wb := f.workbookReader() if wb.PivotCaches == nil { -- cgit v1.2.1