Skip to content

Commit

Permalink
[update_table] check if autofilter is available. closes #802
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Sep 29, 2023
1 parent 8a8ba34 commit d259576
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions R/class-workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -2397,9 +2397,11 @@ wbWorkbook <- R6::R6Class(
tab_attr <- xml_attr(xml, "table")[[1]]
tab_attr[["ref"]] <- dims

tab_autofilter <- xml_node(xml, "table", "autoFilter")
tab_autofilter <- xml_attr_mod(tab_autofilter, xml_attributes = c(ref = dims))

tab_autofilter <- NULL
if ("autofilter" %in% tab_nams) {
tab_autofilter <- xml_node(xml, "table", "autoFilter")
tab_autofilter <- xml_attr_mod(tab_autofilter, xml_attributes = c(ref = dims))
}

tab_tabColumns <- xml_node(xml, "table", "tableColumns")
tab_cols <- names(self$to_df(sheet = sheet, dims = dims))
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,11 @@ test_that("updating table works", {
got <- wb_to_df(wb, named_region = "Table2")
expect_equal(exp, got, ignore_attr = TRUE)

wb <- wb_workbook()$add_worksheet()$add_data_table(x = mtcars, with_filter = FALSE)
wb$update_table(tabname = "Table1", dims = "A1:J4")

exp <- "A1:J4"
got <- wb$tables$tab_ref
expect_equal(exp, got)

})

0 comments on commit d259576

Please sign in to comment.