Skip to content

Commit

Permalink
[slicer] allow setting hide items with no data
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Oct 29, 2024
1 parent 8e89506 commit 1934ca4
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions R/class-workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -1758,8 +1758,8 @@ wbWorkbook <- R6::R6Class(
} else {
arguments <- c(
"caption", "choose", "column_count", "cross_filter", "edit_as",
"level", "locked_position", "row_height", "show_caption",
"show_missing", "sort_order", "start_item", "style"
"hide_no_data_items", "level", "locked_position", "row_height",
"show_caption", "show_missing", "sort_order", "start_item", "style"
)
params <- standardize_case_names(params, arguments = arguments, return = TRUE)
}
Expand Down Expand Up @@ -1819,6 +1819,16 @@ wbWorkbook <- R6::R6Class(
xml_children = get_items(x, which(names(x) == slicer), NULL, slicer = TRUE, choose = choo, has_default = TRUE)
)


hide_items_with_no_data <- ""
if (isTRUE(params$hide_no_data_items)) {
hide_items_with_no_data <- '<extLst>
<x:ext xmlns:x15="http://schemas.microsoft.com/office/spreadsheetml/2010/11/main" uri="{470722E0-AACD-4C17-9CDC-17EF765DBC7E}">
<x15:slicerCacheHideItemsWithNoData/>
</x:ext>
</extLst>'
}

slicer_cache <- read_xml(sprintf(
'<slicerCacheDefinition xmlns="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x xr10" xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:xr10="http://schemas.microsoft.com/office/spreadsheetml/2016/revision10" name="Slicer_%s" xr10:uid="{72B411E0-23B7-7444-B533-EAC1856BE56A}" sourceName="%s">
<pivotTables>
Expand All @@ -1827,12 +1837,14 @@ wbWorkbook <- R6::R6Class(
<data>
%s
</data>
%s
</slicerCacheDefinition>',
uni_name,
slicer,
sheet,
pivot_table,
tab_xml
tab_xml,
hide_items_with_no_data
), pointer = FALSE)

# we need the slicer cache
Expand Down

0 comments on commit 1934ca4

Please sign in to comment.