Skip to content

Commit 6896bc7

Browse files
committed
[write] allow shared formulas without A1 cell reference
1 parent 832f0bc commit 6896bc7

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

NEWS.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# openxlsx2 (development version)
2+
3+
## Fixes
4+
5+
* 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)`
6+
7+
8+
***************************************************************************
9+
110
# openxlsx2 1.12
211

312
## New features

R/write.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ write_data2 <- function(
520520
cc$f_t <- "shared"
521521
cc[1, "f_ref"] <- dims
522522
cc[2:nrow(cc), "f"] <- ""
523-
cc$f_si <- max(int_si) + 1L
523+
cc$f_si <- max(int_si, 0) + 1L
524524
}
525525

526526
if (is.null(wb$worksheets[[sheetno]]$sheet_data$cc)) {

tests/testthat/test-formulas.R

+7
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,13 @@ test_that("writing shared formulas works", {
187187
got <- unique(cc$f_si)
188188
expect_equal(exp, got)
189189

190+
wb <- wb_workbook()$add_worksheet()
191+
wb$add_formula(x = "1", dims = "A1:B1", shared = TRUE)
192+
193+
exp <- "shared"
194+
got <- unique(wb$worksheets[[1]]$sheet_data$cc$f_t)
195+
expect_equal(exp, got)
196+
190197
})
191198

192199
test_that("increase formula dims if required", {

0 commit comments

Comments
 (0)