Skip to content

Commit

Permalink
set a default value to control the position of the slicer. if a singl…
Browse files Browse the repository at this point in the history
…e cell is provided, create a cell range. use editAs = "oneCell". Similar to what redmonds spreadsheet software uses.
  • Loading branch information
JanMarvin committed Oct 21, 2023
1 parent 62f5d7e commit b438f65
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions R/class-workbook-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ wb_add_pivot_table <- function(
wb_add_slicer <- function(
wb,
x,
dims = "B12:D16",
sheet = current_sheet(),
dims = "A1",
sheet = current_sheet(),
pivot_table,
slicer,
params
Expand Down
23 changes: 21 additions & 2 deletions R/class-workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,16 @@ wbWorkbook <- R6::R6Class(
#' @param slicer a variable used as slicer for the pivot table
#' @param params a list of parameters to modify pivot table creation
#' @return The `wbWorkbook` object
add_slicer = function(x, dims = "B12:D16", sheet = current_sheet(), pivot_table, slicer, params) {
add_slicer = function(x, dims = "A1", sheet = current_sheet(), pivot_table, slicer, params) {

if (!grepl(":", dims)) {
ddims <- dims_to_rowcol(dims, as_integer = TRUE)

dims <- rowcol_to_dims(
row = c(ddims[[2]], ddims[[2]] + 12L),
col = c(ddims[[1]], ddims[[1]] + 1L)
)
}

if (missing(x))
stop("x cannot be missing in add_slicer")
Expand Down Expand Up @@ -1650,8 +1659,13 @@ wbWorkbook <- R6::R6Class(
', uni_name, uni_name
), pointer = FALSE)


edit_as <- "oneCell"
if (!is.null(params$edit_as))
edit_as <- params$edit_as

# place the drawing
self$add_drawing(dims = dims, sheet = sheet, xml = drawing_xml)
self$add_drawing(dims = dims, sheet = sheet, xml = drawing_xml, edit_as = edit_as)


next_id <- get_next_id(self$worksheets_rels[[sheet]])
Expand Down Expand Up @@ -4813,7 +4827,9 @@ wbWorkbook <- R6::R6Class(
...
) {

edit_as <- NULL
standardize_case_names(...)
if (!is.null(list(...)$edit_as)) edit_as <- list(...)$edit_as

sheet <- private$get_sheet_index(sheet)

Expand Down Expand Up @@ -4918,6 +4934,9 @@ wbWorkbook <- R6::R6Class(
grpSp,
grFrm,
clDt
),
xml_attributes = c(
editAs = as_xml_attr(edit_as)
)
)

Expand Down
2 changes: 1 addition & 1 deletion man/wbWorkbook.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/wb_add_slicer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b438f65

Please sign in to comment.