Skip to content
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

Can you append to current style? #1173

Open
J-Moravec opened this issue Oct 31, 2024 · 2 comments
Open

Can you append to current style? #1173

J-Moravec opened this issue Oct 31, 2024 · 2 comments

Comments

@J-Moravec
Copy link

I am styling my table according to https://janmarvin.github.io/openxlsx2/articles/openxlsx2_style_manual.html#styling-showcase. I run a lot of wb_add_style, which seems to be rewriting the current style altogether.

Is there a way to append to the current style?

MRE:

wb = wb_workbook() |> wb_add_worksheet("iris") |> wb_add_data("iris", iris, col_names = TRUE, na.strings = "")
# Change first cell to bold
wb = wb_add_font(wb, dims = wb_dims(1, 1), bold = TRUE)
# Now to arial, but bold is removed
wb = wb_add_font(wb, dims = wb_dims(1, 1), name = "Arial") 
 # Now to size 10, but its not bold or Arial any more
wb = wb_add_font(wb, dims = wb_dims(1,1), size = 10)
# wb$open()
@JanMarvin
Copy link
Owner

Hi @J-Moravec ,

there is a PR that can help with this (#1153), but it's still an early draft.

library(openxlsx2)

wb = wb_workbook() |> wb_add_worksheet("iris") |> wb_add_data("iris", iris, col_names = TRUE, na.strings = "")
# Change first cell to bold
wb = wb_add_font(wb, dims = wb_dims(1, 1), bold = TRUE)
# Now to arial, but bold is removed
wb = wb_add_font(wb, dims = wb_dims(1, 1), name = "Arial", update = TRUE) 
# Now to size 10 and bold, but not Arial any more
wb = wb_add_font(wb, dims = wb_dims(1,1), size = 10, update = TRUE)

wb$styles_mgr$styles$fonts[2:4]
#> [1] "<font><b val=\"1\"/><color rgb=\"FF000000\"/><name val=\"Aptos Narrow\"/><sz val=\"11\"/></font>"
#> [2] "<font><b val=\"1\"/><color rgb=\"FF000000\"/><name val=\"Arial\"/><sz val=\"11\"/></font>"       
#> [3] "<font><b val=\"1\"/><color rgb=\"FF000000\"/><name val=\"Aptos Narrow\"/><sz val=\"10\"/></font>"

@JanMarvin
Copy link
Owner

Since we provide default values in wb_add_font() it is not possible to differentiate in updated values or default values.

This works, but hmm

wb = wb_add_font(wb, dims = wb_dims(1,1), name = "", size = 10, update = TRUE)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants