-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Property deleteRows = FALSE
does not work in wb_protect_worksheet()
#871
Comments
Hi @Layalchristine24 , thanks for the report. The issue is a bit tricky as you have to apply row styles where the cell style information: The entire protect/unprotect thing is a bit ... same goes with #872. It's not us, but the openxml specification or better, the excel developers who invented this confusing things. # remotes::install_github("JanMarvin/openxlsx2")
library(palmerpenguins)
library(openxlsx2)
wb_test <- wb_workbook(
datetime_created = Sys.time(),
) %>%
wb_add_worksheet(
sheet = "my_first_sheet"
) %>%
wb_add_data(
x = penguins
) %>%
wb_protect_worksheet(
sheet = "my_first_sheet",
protect = TRUE,
properties = c(
autoFilter = FALSE,
deleteRows = FALSE, # does not work
insertRows = FALSE
)
) %>%
wb_add_cell_style(
dims = wb_dims(x = penguins),
locked = FALSE
)
styid <- wb_test %>% wb_get_cell_style(dims = "A1")
# apply style 2 (extract, modify and insert)
rows <- wb_test$worksheets[[1]]$sheet_data$row_attr
rows$customFormat <- "1"
rows$s <- styid
wb_test$worksheets[[1]]$sheet_data$row_attr <- rows
if (interactive()) wb_open(wb_test) |
@JanMarvin Thank you very much for this solution and the explanations. |
@JanMarvin Sorry, but I have one more question about this solution: why do you set |
I simply picked one cell that has the I can create a more elaborate example later. PS: Just for the reference, I had to google this as well and already typed a "its a Excel bug" reply. |
@JanMarvin Thank you very much! |
If you don’t want to apply the protection to every cell you can add it only to a fraction. Like all columns in rows 1:10 or columns A:D. Subset |
I have implemented a remotes::install_github("JanMarvin/openxlsx2#873")
#> Skipping install of 'openxlsx2' from a github remote, the SHA1 (379b11ed) has not changed since last install.
#> Use `force = TRUE` to force installation
library(palmerpenguins)
library(openxlsx2)
wb_test <- wb_workbook(
datetime_created = Sys.time(),
) %>%
wb_add_worksheet(
sheet = "my_first_sheet"
) %>%
wb_add_data(
x = penguins
) %>%
wb_protect_worksheet(
sheet = "my_first_sheet",
protect = TRUE,
properties = c(
autoFilter = FALSE,
deleteRows = FALSE,
insertRows = FALSE
)
) %>%
wb_add_cell_style(
dims = wb_dims(x = penguins),
locked = FALSE
) %>%
wb_add_style_across(rows = wb_dims(x = penguins))
if (interactive()) wb_open(wb_test) |
@JanMarvin Thank you! However, the function
|
Ah I’ve renamed it to |
@JanMarvin Thank you! My problem is that I need to apply the |
I’m not sure that it is possible to do that with the ooxml format. Either you lock cells or you unlock them and allow their removal |
All Right. Thank you! Is this specific to the openxlsx2 package or is it the same with openxlsx? |
I believe this is specific to the file format. I don’t even think you’re able to create this with Excel |
Ok, thank you very much for your help. |
I've merged pull request #873 and the next release will ship |
Hi! I would like to be able to delete rows even if the worksheet is protected, but it does not seem to work. Thank you for your help!
The text was updated successfully, but these errors were encountered: