Skip to content

Commit

Permalink
[load] Allow newlines in header footer (#1279)
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin authored Feb 25, 2025
1 parent d4f7432 commit dd8d617
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions R/helper-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ amp_split <- function(x) {
# Extract each component if present and remove &amp;[LCR]
if (grepl("&amp;L", x)) {
has[1] <- 1
res[1] <- stringi::stri_extract_first_regex(x, "&amp;L.*?(?=&amp;C|&amp;R|$)")
res[1] <- stringi::stri_extract_first_regex(x, "&amp;L[\\s\\S]*?(?=&amp;C|&amp;R|$)")
}
if (grepl("&amp;C", x)) {
has[2] <- 1
res[2] <- stringi::stri_extract_first_regex(x, "&amp;C.*?(?=&amp;R|$)")
res[2] <- stringi::stri_extract_first_regex(x, "&amp;C[\\s\\S]*?(?=&amp;R|$)")
}
if (grepl("&amp;R", x)) {
has[3] <- 1
res[3] <- stringi::stri_extract_first_regex(x, "&amp;R.*?$")
res[3] <- stringi::stri_extract_first_regex(x, "&amp;R[\\s\\S]*?$")
}

if (sum(has) == 0) return(character(0))
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-loading_workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,17 @@ test_that("test headerFooter", {

})

test_that("linebreaks in header footer work", {
tmp <- temp_xlsx()
wb <- wb_workbook()$add_worksheet()$
set_header_footer(header = c("One\nTwo\nThree", NA, NA))
wb$save(tmp)

wb <- wb_load(tmp)
exp <- "One\nTwo\nThree"
got <- wb$worksheets[[1]]$headerFooter$oddHeader[1]
expect_equal(exp, got)
})

test_that("load workbook with chartsheet", {

Expand Down

0 comments on commit dd8d617

Please sign in to comment.