@@ -667,11 +667,14 @@ pivot_def_rel <- function(n) sprintf("<Relationships xmlns=\"http://schemas.open
667
667
668
668
pivot_xml_rels <- function (n ) sprintf(" <Relationships xmlns=\" http://schemas.openxmlformats.org/package/2006/relationships\" ><Relationship Id=\" rId1\" Type=\" http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition\" Target=\" ../pivotCache/pivotCacheDefinition%s.xml\" /></Relationships>" , n )
669
669
670
- get_items <- function (data , x , item_order , slicer = FALSE , choose = NULL ) {
670
+ get_items <- function (data , x , item_order , slicer = FALSE , choose = NULL , has_default = TRUE ) {
671
671
x <- abs(x )
672
672
673
673
dat <- distinct(data [[x ]])
674
674
675
+ default <- NULL
676
+ if (has_default ) default <- " default"
677
+
675
678
# check length, otherwise a certain spreadsheet software simply dies
676
679
if (! is.null(item_order )) {
677
680
@@ -725,7 +728,7 @@ get_items <- function(data, x, item_order, slicer = FALSE, choose = NULL) {
725
728
USE.NAMES = FALSE
726
729
)
727
730
} else {
728
- vals <- c(item_order - 1L , " default" )
731
+ vals <- c(as.character( item_order - 1L ), default )
729
732
item <- sapply(
730
733
seq_along(vals ),
731
734
# # TODO this sets the order of the pivot elements
@@ -842,7 +845,8 @@ create_pivot_table <- function(
842
845
" show_multiple_label" , " show_row_headers" , " show_row_stripes" ,
843
846
" sort_col" , " sort_item" , " sort_row" , " subtotal_hidden_items" ,
844
847
" table_style" , " tag" , " use_auto_formatting" , " vacated_style" ,
845
- " visual_totals"
848
+ " visual_totals" ,
849
+ " subtotal_top" , " default_subtotal"
846
850
)
847
851
params <- standardize_case_names(params , arguments = arguments , return = TRUE )
848
852
@@ -855,6 +859,22 @@ create_pivot_table <- function(
855
859
if (! is.null(params $ outline ))
856
860
outline <- params $ outline
857
861
862
+ subtotalTop <- NULL
863
+ SubtotalsOnTopDefault <- NULL
864
+ if (! is.null(params $ subtotal_top )) {
865
+ subtotalTop <- as_xml_attr(params $ subtotal_top )
866
+ SubtotalsOnTopDefault <- as_xml_attr(params $ subtotal_top )
867
+ }
868
+
869
+ has_default <- TRUE
870
+ defaultSubtotal <- NULL
871
+ EnabledSubtotalsDefault <- NULL
872
+ if (! is.null(params $ default_subtotal )) {
873
+ has_default <- params $ default_subtotal
874
+ defaultSubtotal <- as_xml_attr(has_default )
875
+ EnabledSubtotalsDefault <- as_xml_attr(has_default )
876
+ }
877
+
858
878
for (i in seq_along(x )) {
859
879
860
880
dataField <- NULL
@@ -917,8 +937,14 @@ create_pivot_table <- function(
917
937
multi <- if (is.null(choose )) NULL else as_xml_attr(TRUE )
918
938
919
939
attrs <- c(
920
- axis , dataField , showAll = " 0" , multipleItemSelectionAllowed = multi , sortType = sort ,
921
- compact = as_xml_attr(compact ), outline = as_xml_attr(outline )
940
+ axis , dataField ,
941
+ subtotalTop = subtotalTop ,
942
+ showAll = " 0" ,
943
+ defaultSubtotal = defaultSubtotal ,
944
+ multipleItemSelectionAllowed = multi ,
945
+ sortType = sort ,
946
+ compact = as_xml_attr(compact ),
947
+ outline = as_xml_attr(outline )
922
948
)
923
949
924
950
if (is_formula ) {
@@ -947,7 +973,7 @@ create_pivot_table <- function(
947
973
tmp <- xml_node_create(
948
974
" pivotField" ,
949
975
xml_attributes = attrs ,
950
- xml_children = paste0(paste0(get_items(x , i , sort_itm , FALSE , choo ), collapse = " " ), autoSortScope ))
976
+ xml_children = paste0(paste0(get_items(x , i , sort_itm , FALSE , choo , has_default ), collapse = " " ), autoSortScope ))
951
977
}
952
978
953
979
pivotField <- c(pivotField , tmp )
@@ -1136,6 +1162,27 @@ create_pivot_table <- function(
1136
1162
if (! is.null(params $ name ))
1137
1163
pivot_table_name <- params $ name
1138
1164
1165
+
1166
+ ptd16 <- xml_node_create(
1167
+ " xpdl:pivotTableDefinition16" ,
1168
+ xml_attributes = c(
1169
+ EnabledSubtotalsDefault = EnabledSubtotalsDefault ,
1170
+ SubtotalsOnTopDefault = SubtotalsOnTopDefault
1171
+ )
1172
+ )
1173
+
1174
+ extLst <- sprintf(
1175
+ ' <extLst>
1176
+ <ext uri="{962EF5D1-5CA2-4c93-8EF4-DBF5C05439D2}" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main">
1177
+ <x14:pivotTableDefinition hideValuesRow="1" xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main" />
1178
+ </ext>
1179
+ <ext uri="{747A6164-185A-40DC-8AA5-F01512510D54}" xmlns:xpdl="http://schemas.microsoft.com/office/spreadsheetml/2016/pivotdefaultlayout">
1180
+ %s
1181
+ </ext>
1182
+ </extLst>' ,
1183
+ ptd16
1184
+ )
1185
+
1139
1186
xml_node_create(
1140
1187
" pivotTableDefinition" ,
1141
1188
xml_attributes = c(
@@ -1220,8 +1267,8 @@ create_pivot_table <- function(
1220
1267
colsFields ,
1221
1268
pageFields ,
1222
1269
dataFields ,
1223
- pivotTableStyleInfo
1224
- # extLst
1270
+ pivotTableStyleInfo ,
1271
+ extLst
1225
1272
)
1226
1273
)
1227
1274
0 commit comments