forked from p30928647/excelize
Pivot table generation fails when no Columns and multiple Data are provided. (#708)
fix to create pivot table in case there is no input from Columns Co-authored-by: Jin Kim <jinhyuk.kim@cerence.com> Co-authored-by: xuri <xuri.me@gmail.com>
This commit is contained in:
parent
89465f41b5
commit
c492220237
|
@ -460,6 +460,15 @@ func inPivotTableField(a []PivotTableField, x string) int {
|
|||
// definition and option.
|
||||
func (f *File) addPivotColFields(pt *xlsxPivotTableDefinition, opt *PivotTableOption) error {
|
||||
if len(opt.Columns) == 0 {
|
||||
if len(opt.Data) <= 1 {
|
||||
return nil
|
||||
}
|
||||
pt.ColFields = &xlsxColFields{}
|
||||
// in order to create pivot table in case there is no input from Columns
|
||||
pt.ColFields.Count = 1
|
||||
pt.ColFields.Field = append(pt.ColFields.Field, &xlsxField{
|
||||
X: -2,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ func TestAddPivotTable(t *testing.T) {
|
|||
DataRange: "Sheet1!$A$1:$E$31",
|
||||
PivotTableRange: "Sheet1!$AE$2:$AG$33",
|
||||
Rows: []PivotTableField{{Data: "Month", DefaultSubtotal: true}, {Data: "Year"}},
|
||||
Data: []PivotTableField{{Data: "Sales", Subtotal: "Max", Name: "Summarize by Max"}},
|
||||
Data: []PivotTableField{{Data: "Sales", Subtotal: "Max", Name: "Summarize by Max"}, {Data: "Sales", Subtotal: "Average", Name: "Average of Sales"}},
|
||||
RowGrandTotals: true,
|
||||
ColGrandTotals: true,
|
||||
ShowDrill: true,
|
||||
|
@ -98,7 +98,7 @@ func TestAddPivotTable(t *testing.T) {
|
|||
PivotTableRange: "Sheet1!$AJ$2:$AP1$35",
|
||||
Rows: []PivotTableField{{Data: "Month", DefaultSubtotal: true}, {Data: "Year"}},
|
||||
Filter: []PivotTableField{{Data: "Region"}},
|
||||
Columns: []PivotTableField{{Data: "Type", DefaultSubtotal: true}},
|
||||
Columns: []PivotTableField{},
|
||||
Data: []PivotTableField{{Subtotal: "Sum", Name: "Summarize by Sum"}},
|
||||
RowGrandTotals: true,
|
||||
ColGrandTotals: true,
|
||||
|
|
Loading…
Reference in New Issue