@@ -90,6 +90,10 @@ type PivotTableOptions struct {
9090// NumFmt specifies the number format ID of the data field, this filed only
9191// accepts built-in number format ID and does not support custom number format
9292// expression currently.
93+ //
94+ // SelectedItems specifies the default selected items in a pivot table field.
95+ // The selected items must be values within the cell range referenced by that
96+ // field.
9397type PivotTableField struct {
9498 Compact bool
9599 Data string
@@ -107,7 +111,7 @@ type PivotTableField struct {
107111// options. Note that the same fields can not in Columns, Rows and Filter
108112// fields at the same time.
109113//
110- // For example, create a pivot table on the range reference Sheet1!G2:M34 with
114+ // For example, create a pivot table on the range reference Sheet1!G4:M31 with
111115// the range reference Sheet1!A1:E31 as the data source, summarize by sum for
112116// revenue:
113117//
@@ -127,13 +131,17 @@ type PivotTableField struct {
127131// }
128132// }()
129133// // Create some data in a sheet
130- // month := []string{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
134+ // month := []string{"Jan", "Feb", "Mar", "Apr", "May",
135+ // "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
131136// year := []int{2017, 2018, 2019}
132137// types := []string{"Meat", "Dairy", "Beverages", "Produce"}
133138// revenue := []int{3217, 4512, 3891, 4738, 3054, 4265, 3643, 4901, 3378, 4126}
134139// region := []string{"East", "West", "North", "South"}
135- // if err := f.SetSheetRow("Sheet1", "A1", &[]string{"Month", "Year", "Type", "Revenue", "Region"}); err != nil {
140+ // if err := f.SetSheetRow(
141+ // "Sheet1", "A1", &[]string{"Month", "Year", "Type", "Revenue", "Region"},
142+ // ); err != nil {
136143// fmt.Println(err)
144+ // return
137145// }
138146// for row := 2; row < 32; row++ {
139147// f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), month[(row-2)%len(month)])
@@ -144,19 +152,27 @@ type PivotTableField struct {
144152// }
145153// if err := f.AddPivotTable(&excelize.PivotTableOptions{
146154// DataRange: "Sheet1!A1:E31",
147- // PivotTableRange: "Sheet1!G2:M34",
148- // Rows: []excelize.PivotTableField{{Data: "Month", DefaultSubtotal: true}, {Data: "Year"}},
149- // Filter: []excelize.PivotTableField{{Data: "Region"}},
150- // Columns: []excelize.PivotTableField{{Data: "Type", DefaultSubtotal: true}},
151- // Data: []excelize.PivotTableField{{Data: "Revenue", Name: "Summarize", Subtotal: "Sum"}},
152- // RowGrandTotals: true,
153- // ColGrandTotals: true,
154- // ShowDrill: true,
155- // ShowRowHeaders: true,
156- // ShowColHeaders: true,
157- // ShowLastColumn: true,
155+ // PivotTableRange: "Sheet1!G4:M30",
156+ // Rows: []excelize.PivotTableField{
157+ // {Data: "Month", DefaultSubtotal: true}, {Data: "Year"},
158+ // },
159+ // Filter: []excelize.PivotTableField{
160+ // {Data: "Region"}},
161+ // Columns: []excelize.PivotTableField{
162+ // {Data: "Type", DefaultSubtotal: true},
163+ // },
164+ // Data: []excelize.PivotTableField{
165+ // {Data: "Revenue", Name: "Summarize", Subtotal: "Sum"},
166+ // },
167+ // RowGrandTotals: true,
168+ // ColGrandTotals: true,
169+ // ShowDrill: true,
170+ // ShowRowHeaders: true,
171+ // ShowColHeaders: true,
172+ // ShowLastColumn: true,
158173// }); err != nil {
159174// fmt.Println(err)
175+ // return
160176// }
161177// if err := f.SaveAs("Book1.xlsx"); err != nil {
162178// fmt.Println(err)
0 commit comments