Skip to content

Commit af422e1

Browse files
committed
This closes qax-os#1954 and closes qax-os#2051, fix get pivot tables panic in some case
1 parent 4b4d4df commit af422e1

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

pivotTable.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -899,14 +899,27 @@ func (f *File) getPivotTable(sheet, pivotTableXML, pivotCacheRels string) (Pivot
899899
opts.ShowLastColumn = si.ShowLastColumn
900900
opts.PivotTableStyleName = si.Name
901901
}
902-
order, err := f.getTableFieldsOrder(&opts)
903-
if err != nil {
902+
if err = f.getPivotTableDataRange(&opts); err != nil {
904903
return opts, err
905904
}
906-
f.extractPivotTableFields(order, pt, &opts)
905+
f.extractPivotTableFields(pc.getPivotCacheFieldsName(), pt, &opts)
907906
return opts, err
908907
}
909908

909+
// getPivotCacheFieldsName returns pivot table fields name list by order from
910+
// pivot cache fields.
911+
func (pc *xlsxPivotCacheDefinition) getPivotCacheFieldsName() []string {
912+
var order []string
913+
if pc.CacheFields != nil {
914+
for _, cf := range pc.CacheFields.CacheField {
915+
if cf != nil {
916+
order = append(order, cf.Name)
917+
}
918+
}
919+
}
920+
return order
921+
}
922+
910923
// pivotTableReader provides a function to get the pointer to the structure
911924
// after deserialization of xl/pivotTables/pivotTable%d.xml.
912925
func (f *File) pivotTableReader(path string) (*xlsxPivotTableDefinition, error) {

0 commit comments

Comments
 (0)