Skip to content

Commit

Permalink
Merge pull request #282 from JanMarvin/gh_issue_279
Browse files Browse the repository at this point in the history
fix visibility issue. fixes #279
  • Loading branch information
JanMarvin authored Oct 30, 2021
2 parents f890014 + 2ca1219 commit 4e45e8c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/loadWorkbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ loadWorkbook <- function(file, xlsxFile = NULL, isUnzipped = FALSE) {


is_chart_sheet <- sheetrId %in% chartSheetRIds
is_visible <- !grepl("hidden", unlist(strsplit(sheets, split = "<sheet ")[-1]))
is_visible <- !grepl("hidden", sheets)
if (length(is_visible) != length(sheetrId)) {
is_visible <- rep(TRUE, length(sheetrId))
}
Expand Down
Binary file added inst/extdata/ColorTabs3.xlsx
Binary file not shown.
30 changes: 30 additions & 0 deletions tests/testthat/test-loading_workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -1012,3 +1012,33 @@ test_that("read nodes", {
expect_equal(test, that)

})

test_that("sheet visibility", {

# example is rather slow (lots of hidden cols)
fl <- system.file("extdata", "ColorTabs3.xlsx", package = "openxlsx")
tmp_dir <- temp_xlsx()

exp_sheets <- c("Nums", "Chars", "hidden")
exp_vis <- c("visible", "visible", "hidden")

# after load
wb <- loadWorkbook(fl)
wb_sheets <- openxlsx::sheets(wb)
wb_vis <- openxlsx::sheetVisibility(wb)

# save
saveWorkbook(wb, tmp_dir)

# re-import
wb2 <- loadWorkbook(tmp_dir)
wb2_sheets <- openxlsx::sheets(wb)
wb2_vis <- openxlsx::sheetVisibility(wb)

expect_equal(exp_sheets, wb_sheets)
expect_equal(exp_vis, wb_vis)

expect_equal(exp_sheets, wb2_sheets)
expect_equal(exp_vis, wb2_vis)

})

0 comments on commit 4e45e8c

Please sign in to comment.