未验证 提交 c4922202 编写于 作者: J jinhyuk-kim-ca 提交者: GitHub

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: NJin Kim <jinhyuk.kim@cerence.com>
Co-authored-by: xurime's avatarxuri <xuri.me@gmail.com>
上级 89465f41
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册