diff --git a/R/class-workbook-wrappers.R b/R/class-workbook-wrappers.R
index 4def7f6f3..978c74612 100644
--- a/R/class-workbook-wrappers.R
+++ b/R/class-workbook-wrappers.R
@@ -3101,6 +3101,7 @@ wb_add_form_control <- function(
#' @param style A style to apply to those cells that satisfy the rule. Default is 'font_color = "FF9C0006"' and 'bgFill = "FFFFC7CE"'
#' @param type The type of conditional formatting rule to apply.
#' @param params Additional parameters passed. See **Details** for more
+#' @param ... additional arguments
#' @details See Examples.
#'
#' @details
@@ -3165,8 +3166,6 @@ wb_add_conditional_formatting <- function(
wb,
sheet = current_sheet(),
dims = NULL,
- cols = NULL,
- rows = NULL,
rule = NULL,
style = NULL,
type = c(
@@ -3185,18 +3184,18 @@ wb_add_conditional_formatting <- function(
border = TRUE,
percent = FALSE,
rank = 5L
- )
+ ),
+ ...
) {
assert_workbook(wb)
wb$clone()$add_conditional_formatting(
- sheet = sheet,
- dims = dims,
- cols = cols,
- rows = rows,
- rule = rule,
- style = style,
- type = type,
- params = params
+ sheet = sheet,
+ dims = dims,
+ rule = rule,
+ style = style,
+ type = type,
+ params = params,
+ ... = ...
)
}
diff --git a/R/class-workbook.R b/R/class-workbook.R
index 9edbc1b95..60888e170 100644
--- a/R/class-workbook.R
+++ b/R/class-workbook.R
@@ -3874,18 +3874,15 @@ wbWorkbook <- R6::R6Class(
#' @description Add conditional formatting
#' @param sheet sheet
#' @param dims dims
- #' @param cols cols
- #' @param rows rows
#' @param rule rule
#' @param style style
#' @param type type
#' @param params Additional parameters
+ #' @param ... additional arguments
#' @returns The `wbWorkbook` object
add_conditional_formatting = function(
sheet = current_sheet(),
dims = NULL,
- cols = NULL,
- rows = NULL,
rule = NULL,
style = NULL,
# TODO add vector of possible values
@@ -3905,18 +3902,34 @@ wbWorkbook <- R6::R6Class(
border = TRUE,
percent = FALSE,
rank = 5L
- )
+ ),
+ ...
) {
+ cols <- list(...)[["cols"]]
+ rows <- list(...)[["rows"]]
+
+ if (!is.null(rows) && !is.null(cols)) {
+
+ if (length(cols) > 2 && any(diff(cols) != 1))
+ warning("cols > 2, will create range from min to max.")
+
+ if (getOption("openxlsx2.soon_deprecated", default = FALSE))
+ .Deprecated(old = "cols/rows", new = "dims", package = "openxlsx2")
+
+ dims <- rowcol_to_dims(rows, cols)
+ }
+
+ ddims <- dims_to_rowcol(dims, as_integer = TRUE)
+ rows <- ddims[[2]]
+ cols <- ddims[[1]]
+
if (!is.null(style)) assert_class(style, "character")
assert_class(type, "character")
assert_class(params, "list")
type <- match.arg(type)
- if (length(cols) > 2 && any(diff(cols) != 1))
- warning("cols > 2, will create range from min to max.")
-
## rows and cols
if (!is.null(cols) && !is.null(rows)) {
if (!is.numeric(cols)) {
diff --git a/man/wbWorkbook.Rd b/man/wbWorkbook.Rd
index c2a4a15f2..5222a5455 100644
--- a/man/wbWorkbook.Rd
+++ b/man/wbWorkbook.Rd
@@ -1716,8 +1716,6 @@ Add conditional formatting
\if{html}{\out{
}}\preformatted{wbWorkbook$add_conditional_formatting(
sheet = current_sheet(),
dims = NULL,
- cols = NULL,
- rows = NULL,
rule = NULL,
style = NULL,
type = c("expression", "colorScale", "dataBar", "iconSet", "duplicatedValues",
@@ -1725,7 +1723,8 @@ Add conditional formatting
"notContainsBlanks", "containsText", "notContainsText", "beginsWith", "endsWith",
"between", "topN", "bottomN"),
params = list(showValue = TRUE, gradient = TRUE, border = TRUE, percent = FALSE, rank =
- 5L)
+ 5L),
+ ...
)}\if{html}{\out{
}}
}
@@ -1736,10 +1735,6 @@ Add conditional formatting
\item{\code{dims}}{dims}
-\item{\code{cols}}{cols}
-
-\item{\code{rows}}{rows}
-
\item{\code{rule}}{rule}
\item{\code{style}}{style}
@@ -1747,6 +1742,8 @@ Add conditional formatting
\item{\code{type}}{type}
\item{\code{params}}{Additional parameters}
+
+\item{\code{...}}{additional arguments}
}
\if{html}{\out{}}
}
diff --git a/man/wb_add_conditional_formatting.Rd b/man/wb_add_conditional_formatting.Rd
index 0f8dce8d3..2e114c48b 100644
--- a/man/wb_add_conditional_formatting.Rd
+++ b/man/wb_add_conditional_formatting.Rd
@@ -8,8 +8,6 @@ wb_add_conditional_formatting(
wb,
sheet = current_sheet(),
dims = NULL,
- cols = NULL,
- rows = NULL,
rule = NULL,
style = NULL,
type = c("expression", "colorScale", "dataBar", "iconSet", "duplicatedValues",
@@ -17,7 +15,8 @@ wb_add_conditional_formatting(
"notContainsBlanks", "containsText", "notContainsText", "beginsWith", "endsWith",
"between", "topN", "bottomN"),
params = list(showValue = TRUE, gradient = TRUE, border = TRUE, percent = FALSE, rank =
- 5L)
+ 5L),
+ ...
)
}
\arguments{
@@ -27,10 +26,6 @@ wb_add_conditional_formatting(
\item{dims}{A cell or cell range like "A1" or "A1:B2"}
-\item{cols}{Columns to apply conditional formatting to}
-
-\item{rows}{Rows to apply conditional formatting to}
-
\item{rule}{The condition under which to apply the formatting. See examples.}
\item{style}{A style to apply to those cells that satisfy the rule. Default is 'font_color = "FF9C0006"' and 'bgFill = "FFFFC7CE"'}
@@ -38,6 +33,12 @@ wb_add_conditional_formatting(
\item{type}{The type of conditional formatting rule to apply.}
\item{params}{Additional parameters passed. See \strong{Details} for more}
+
+\item{...}{additional arguments}
+
+\item{cols}{Columns to apply conditional formatting to}
+
+\item{rows}{Rows to apply conditional formatting to}
}
\description{
Add conditional formatting to cells
diff --git a/tests/testthat/test-conditional_formatting.R b/tests/testthat/test-conditional_formatting.R
index fa41347b1..ab205d78f 100644
--- a/tests/testthat/test-conditional_formatting.R
+++ b/tests/testthat/test-conditional_formatting.R
@@ -680,7 +680,7 @@ test_that("containsErrors works", {
wb$add_data(x = c(1, NaN), colNames = FALSE)
wb$add_data(x = c(1, NaN), colNames = FALSE, startCol = 2)
wb$add_conditional_formatting(cols = 1, rows = 1:3, type = "containsErrors")
- wb$add_conditional_formatting(col = 2, rows = 1:3, type = "notContainsErrors")
+ wb$add_conditional_formatting(cols = 2, rows = 1:3, type = "notContainsErrors")
exp <- c(
"ISERROR(A1:A3)",