From 3d4ce6e55ae8433a50edda8066d4231580c65d8c Mon Sep 17 00:00:00 2001 From: Jan Marvin Garbuszus Date: Mon, 23 Dec 2024 18:56:31 +0100 Subject: [PATCH] [write] share formulas without A1 cell reference (#1223) * [misc] begin new development * [write] allow shared formulas without A1 cell reference --- DESCRIPTION | 2 +- NEWS.md | 9 +++++++++ R/write.R | 2 +- tests/testthat/test-formulas.R | 7 +++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index cbea648d7..f33567549 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: openxlsx2 Title: Read, Write and Edit 'xlsx' Files -Version: 1.12 +Version: 1.12.0.9000 Language: en-US Authors@R: c( person("Jordan Mark", "Barbone", email = "jmbarbone@gmail.com", role = "aut", comment = c(ORCID = "0000-0001-9788-3628")), diff --git a/NEWS.md b/NEWS.md index 7860cf42c..8807869e5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,12 @@ +# openxlsx2 (development version) + +## Fixes + +* Formulas that do not have a `A1` cell reference to increase, are now shareable too. `wb_add_formula(x = "1", dims = "A1:A2", shared = TRUE)` + + +*************************************************************************** + # openxlsx2 1.12 ## New features diff --git a/R/write.R b/R/write.R index 489d5f20d..51bff5d9d 100644 --- a/R/write.R +++ b/R/write.R @@ -520,7 +520,7 @@ write_data2 <- function( cc$f_t <- "shared" cc[1, "f_ref"] <- dims cc[2:nrow(cc), "f"] <- "" - cc$f_si <- max(int_si) + 1L + cc$f_si <- max(int_si, -1L) + 1L } if (is.null(wb$worksheets[[sheetno]]$sheet_data$cc)) { diff --git a/tests/testthat/test-formulas.R b/tests/testthat/test-formulas.R index 4274d2d18..85c9cc424 100644 --- a/tests/testthat/test-formulas.R +++ b/tests/testthat/test-formulas.R @@ -187,6 +187,13 @@ test_that("writing shared formulas works", { got <- unique(cc$f_si) expect_equal(exp, got) + wb <- wb_workbook()$add_worksheet() + wb$add_formula(x = "1", dims = "A1:B1", shared = TRUE) + + exp <- "shared" + got <- unique(wb$worksheets[[1]]$sheet_data$cc$f_t) + expect_equal(exp, got) + }) test_that("increase formula dims if required", {