Skip to content

Commit

Permalink
This closes #1954 and closes #2051, fix get pivot tables panic in som…
Browse files Browse the repository at this point in the history
…e case
  • Loading branch information
xuri committed Jan 5, 2025
1 parent 4b4d4df commit af422e1
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions pivotTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -899,14 +899,27 @@ func (f *File) getPivotTable(sheet, pivotTableXML, pivotCacheRels string) (Pivot
opts.ShowLastColumn = si.ShowLastColumn
opts.PivotTableStyleName = si.Name
}
order, err := f.getTableFieldsOrder(&opts)
if err != nil {
if err = f.getPivotTableDataRange(&opts); err != nil {
return opts, err
}
f.extractPivotTableFields(order, pt, &opts)
f.extractPivotTableFields(pc.getPivotCacheFieldsName(), pt, &opts)
return opts, err
}

// getPivotCacheFieldsName returns pivot table fields name list by order from
// pivot cache fields.
func (pc *xlsxPivotCacheDefinition) getPivotCacheFieldsName() []string {
var order []string
if pc.CacheFields != nil {
for _, cf := range pc.CacheFields.CacheField {
if cf != nil {
order = append(order, cf.Name)
}
}
}
return order
}

// pivotTableReader provides a function to get the pointer to the structure
// after deserialization of xl/pivotTables/pivotTable%d.xml.
func (f *File) pivotTableReader(path string) (*xlsxPivotTableDefinition, error) {
Expand Down

0 comments on commit af422e1

Please sign in to comment.