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

[styles] allow updates of font elements #1153

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

JanMarvin
Copy link
Owner

Related to this SO. If update = TRUE all non empty font elements will be overwritten. At the moment it is not possible to set a font element to missing. All elements are initialized with either "" or some value. Might need some additional thinking

library(openxlsx2)

wb <- wb_workbook() |>
  wb_add_worksheet() |>
  wb_add_data(x = letters) |>
  wb_add_font(dims = wb_dims(x = letters), name = "Calibri", size = 20) |>
  # updates only the font color
  wb_add_font(dims = wb_dims(x = letters), name = "", size = "", color = wb_color("orange"), update = TRUE)

if (interactive()) wb$open()

@JanMarvin
Copy link
Owner Author

I'm lacking a bit the motivation to work on this. Maybe someone else wants to pick it up.

Issues I see that I wanted to work on or at least get checked prior to merging:

  • Do we have to do the same for other style objects? numfmts only has numfmts, fill has various other options, what about cell styles in general?
  • It's subpar that we have defaults defined for the font arguments and if we want to avoid having these updated, have to pass "" to "trick" update into not using the default values. At the moment I do not see any better solution other than changing the default arguments of the function to NULL and do some further work on the fonts code and I'm not sure I like that. How else should the function know, if the font name to use is the actual default value or the value that we want after updating.
  • How does updating parts of the font styles impact named themes? Are they broken afterwards, are they impacted at all?
  • This wont impact colors of fmt_txt() strings. These will remain in their own color, because the color is embedded in the XML string of the string, not of the cell format. Should we warn?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 😀 New feature or request help wanted 🙏 Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant