diff --git a/NEWS.md b/NEWS.md index 371349d02..25622925e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -26,6 +26,8 @@ * Order of arguments in `wb_add_conditional_formatting()` changed, because previously overlooked `dims` argument was added. [642](https://github.com/JanMarvin/openxlsx2/pull/642) +* New argument `gradientFill` was added to `create_dxfs_style()`. [651](https://github.com/JanMarvin/openxlsx2/pull/6501 + *************************************************************************** diff --git a/R/wb_styles.R b/R/wb_styles.R index d059a9e86..43fe2469e 100644 --- a/R/wb_styles.R +++ b/R/wb_styles.R @@ -667,6 +667,7 @@ get_cell_styles <- function(wb, sheet, cell) { #' @param border_style "thin" #' @param bgFill Cell background fill color. #' @param fgColor Cell foreground fill color. +#' @param gradientFill An xml string beginning with ... #' @param text_bold bold #' @param text_strike strikeout #' @param text_italic italic @@ -706,6 +707,7 @@ create_dxfs_style <- function( border_style = getOption("openxlsx2.borderStyle", "thin"), bgFill = NULL, fgColor = NULL, + gradientFill = NULL, text_bold = NULL, text_strike = NULL, text_italic = NULL, @@ -742,8 +744,14 @@ create_dxfs_style <- function( patternType <- "solid" } - if (!is.null(bgFill) && !all(bgFill == "")) { - fill <- create_fill(patternType = patternType, bgColor = bgFill, fgColor = fgColor) + if (!is.null(bgFill) && !all(bgFill == "") || !is.null(gradientFill)) { + if (is.null(gradientFill)) { + # gradientFill is an xml string + gradientFill <- "" + } else { + patternType <- "" + } + fill <- create_fill(patternType = patternType, bgColor = bgFill, fgColor = fgColor, gradientFill = gradientFill) } else { fill <- NULL } diff --git a/man/create_dxfs_style.Rd b/man/create_dxfs_style.Rd index 5793a42f0..b6f6ba7ef 100644 --- a/man/create_dxfs_style.Rd +++ b/man/create_dxfs_style.Rd @@ -14,6 +14,7 @@ create_dxfs_style( border_style = getOption("openxlsx2.borderStyle", "thin"), bgFill = NULL, fgColor = NULL, + gradientFill = NULL, text_bold = NULL, text_strike = NULL, text_italic = NULL, @@ -44,6 +45,8 @@ or one of colors(). If fontColor is NULL, the workbook base font colors is used. \item{fgColor}{Cell foreground fill color.} +\item{gradientFill}{An xml string beginning with \if{html}{\out{}} ...} + \item{text_bold}{bold} \item{text_strike}{strikeout} diff --git a/tests/testthat/test-conditional_formatting.R b/tests/testthat/test-conditional_formatting.R index 7385dbfb4..c627caf9a 100644 --- a/tests/testthat/test-conditional_formatting.R +++ b/tests/testthat/test-conditional_formatting.R @@ -767,3 +767,26 @@ test_that("un_list works", { expect_equal(pre_save, post_save) }) + +test_that("conditional formatting with gradientFill works", { + + gf <- read_xml( + " + + + ", + pointer = FALSE) + + gf_style <- create_dxfs_style(gradientFill = gf) + + wb <- wb_workbook()$ + add_worksheet()$ + add_data(x = 1)$ + add_conditional_formatting(cols = 1, rows = 1, rule = "==1", style = "gf_style")$ + add_style(gf_style) + + exp <- "" + got <- wb$styles_mgr$styles$dxfs + expect_equal(exp, got) + +})