Skip to content

Commit

Permalink
Merge pull request qax-os#710 from lbraconnier2/Pivot-failed-in-case-…
Browse files Browse the repository at this point in the history
…of-multi-columns-and-multi-data

fix pivot fails in case of multi columns and multi data
  • Loading branch information
xuri authored Oct 1, 2020
2 parents c492220 + 2bd359b commit 9055a83
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pivotTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,13 @@ func (f *File) addPivotColFields(pt *xlsxPivotTableDefinition, opt *PivotTableOp
})
}

//in order to create pivot in case there is many Columns and Many Datas
if len(opt.Data) > 1 {
pt.ColFields.Field = append(pt.ColFields.Field, &xlsxField{
X: -2,
})
}

// count col fields
pt.ColFields.Count = len(pt.ColFields.Field)
return err
Expand Down
14 changes: 14 additions & 0 deletions pivotTable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ func TestAddPivotTable(t *testing.T) {
ShowColHeaders: true,
ShowLastColumn: true,
}))
//Test Pivot table with many data, many rows, many cols
assert.NoError(t, f.AddPivotTable(&PivotTableOption{
DataRange: "Sheet1!$A$1:$E$31",
PivotTableRange: "Sheet2!$A$56:$AG$90",
Rows: []PivotTableField{{Data: "Month", DefaultSubtotal: true}, {Data: "Year"}},
Columns: []PivotTableField{{Data: "Region", DefaultSubtotal: true}, {Data: "Type"}},
Data: []PivotTableField{{Data: "Sales", Subtotal: "Sum", Name: "Sum of Sales"}, {Data: "Sales", Subtotal: "Average", Name: "Average of Sales"}},
RowGrandTotals: true,
ColGrandTotals: true,
ShowDrill: true,
ShowRowHeaders: true,
ShowColHeaders: true,
ShowLastColumn: true,
}))

// Test empty pivot table options
assert.EqualError(t, f.AddPivotTable(nil), "parameter is required")
Expand Down

0 comments on commit 9055a83

Please sign in to comment.