@@ -19,6 +19,13 @@ import (
19
19
)
20
20
21
21
// PivotTableOption directly maps the format settings of the pivot table.
22
+ //
23
+ // PivotTableStyleName: The built-in pivot table style names
24
+ //
25
+ // PivotStyleLight1 - PivotStyleLight28
26
+ // PivotStyleMedium1 - PivotStyleMedium28
27
+ // PivotStyleDark1 - PivotStyleDark28
28
+ //
22
29
type PivotTableOption struct {
23
30
pivotTableSheetName string
24
31
DataRange string
@@ -63,8 +70,10 @@ type PivotTableOption struct {
63
70
// Name specifies the name of the data field. Maximum 255 characters
64
71
// are allowed in data field name, excess characters will be truncated.
65
72
type PivotTableField struct {
73
+ Compact bool
66
74
Data string
67
75
Name string
76
+ Outline bool
68
77
Subtotal string
69
78
DefaultSubtotal bool
70
79
}
@@ -277,13 +286,13 @@ func (f *File) addPivotCache(pivotCacheID int, pivotCacheXML string, opt *PivotT
277
286
pc .CacheSource .WorksheetSource = & xlsxWorksheetSource {Name : opt .DataRange }
278
287
}
279
288
for _ , name := range order {
280
- defaultRowsSubtotal , rowOk := f .getPivotTableFieldNameDefaultSubtotal (name , opt .Rows )
281
- defaultColumnsSubtotal , colOk := f .getPivotTableFieldNameDefaultSubtotal (name , opt .Columns )
289
+ rowOptions , rowOk := f .getPivotTableFieldOptions (name , opt .Rows )
290
+ columnOptions , colOk := f .getPivotTableFieldOptions (name , opt .Columns )
282
291
sharedItems := xlsxSharedItems {
283
292
Count : 0 ,
284
293
}
285
294
s := xlsxString {}
286
- if (rowOk && ! defaultRowsSubtotal ) || (colOk && ! defaultColumnsSubtotal ) {
295
+ if (rowOk && ! rowOptions . DefaultSubtotal ) || (colOk && ! columnOptions . DefaultSubtotal ) {
287
296
s = xlsxString {
288
297
V : "" ,
289
298
}
@@ -522,22 +531,24 @@ func (f *File) addPivotFields(pt *xlsxPivotTableDefinition, opt *PivotTableOptio
522
531
x := 0
523
532
for _ , name := range order {
524
533
if inPivotTableField (opt .Rows , name ) != - 1 {
525
- defaultSubtotal , ok := f .getPivotTableFieldNameDefaultSubtotal (name , opt .Rows )
534
+ rowOptions , ok := f .getPivotTableFieldOptions (name , opt .Rows )
526
535
var items []* xlsxItem
527
- if ! ok || ! defaultSubtotal {
536
+ if ! ok || ! rowOptions . DefaultSubtotal {
528
537
items = append (items , & xlsxItem {X : & x })
529
538
} else {
530
539
items = append (items , & xlsxItem {T : "default" })
531
540
}
532
541
533
542
pt .PivotFields .PivotField = append (pt .PivotFields .PivotField , & xlsxPivotField {
534
- Axis : "axisRow" ,
535
- Name : f .getPivotTableFieldName (name , opt .Rows ),
543
+ Name : f .getPivotTableFieldName (name , opt .Rows ),
544
+ Axis : "axisRow" ,
545
+ Compact : & rowOptions .Compact ,
546
+ Outline : & rowOptions .Outline ,
547
+ DefaultSubtotal : & rowOptions .DefaultSubtotal ,
536
548
Items : & xlsxItems {
537
549
Count : len (items ),
538
550
Item : items ,
539
551
},
540
- DefaultSubtotal : & defaultSubtotal ,
541
552
})
542
553
continue
543
554
}
@@ -555,21 +566,23 @@ func (f *File) addPivotFields(pt *xlsxPivotTableDefinition, opt *PivotTableOptio
555
566
continue
556
567
}
557
568
if inPivotTableField (opt .Columns , name ) != - 1 {
558
- defaultSubtotal , ok := f .getPivotTableFieldNameDefaultSubtotal (name , opt .Columns )
569
+ columnOptions , ok := f .getPivotTableFieldOptions (name , opt .Columns )
559
570
var items []* xlsxItem
560
- if ! ok || ! defaultSubtotal {
571
+ if ! ok || ! columnOptions . DefaultSubtotal {
561
572
items = append (items , & xlsxItem {X : & x })
562
573
} else {
563
574
items = append (items , & xlsxItem {T : "default" })
564
575
}
565
576
pt .PivotFields .PivotField = append (pt .PivotFields .PivotField , & xlsxPivotField {
566
- Axis : "axisCol" ,
567
- Name : f .getPivotTableFieldName (name , opt .Columns ),
577
+ Name : f .getPivotTableFieldName (name , opt .Columns ),
578
+ Axis : "axisCol" ,
579
+ Compact : & columnOptions .Compact ,
580
+ Outline : & columnOptions .Outline ,
581
+ DefaultSubtotal : & columnOptions .DefaultSubtotal ,
568
582
Items : & xlsxItems {
569
583
Count : len (items ),
570
584
Item : items ,
571
585
},
572
- DefaultSubtotal : & defaultSubtotal ,
573
586
})
574
587
continue
575
588
}
@@ -669,13 +682,15 @@ func (f *File) getPivotTableFieldName(name string, fields []PivotTableField) str
669
682
return ""
670
683
}
671
684
672
- func (f * File ) getPivotTableFieldNameDefaultSubtotal (name string , fields []PivotTableField ) (bool , bool ) {
685
+ // getPivotTableFieldOptions return options for specific field by given field name.
686
+ func (f * File ) getPivotTableFieldOptions (name string , fields []PivotTableField ) (options PivotTableField , ok bool ) {
673
687
for _ , field := range fields {
674
688
if field .Data == name {
675
- return field .DefaultSubtotal , true
689
+ options , ok = field , true
690
+ return
676
691
}
677
692
}
678
- return false , false
693
+ return
679
694
}
680
695
681
696
// addWorkbookPivotCache add the association ID of the pivot cache in workbook.xml.
0 commit comments