openxlsx2
openxlsx2 copied to clipboard
`wbStyle` enchancements
These are pulled out from #9. Didn't want it holding up the issue.
May want to look at parity with #6, #36. Haven't started on this yet, maybe a bit of a duplicate effort.
Some additional steps to make creating a new wbStyle
object quicker and easier to handle. These changes would also move a lot of the checks outside of the initialize()
function and into the specs, which should make it a bit more clear what needs to be checked. It could also give us some template to extract styles from existing workbooks and make sure we have roundtrip styles.
Todos
- [ ] create
wb_font_specs()
to simplify includingfontId
,fontName
,fontColour
,fontSize
,fontFamily
,fontScheme
,fontDecoration
- [ ] create
wb_border_specs()
to simplify includingborderTop
,borderLeft
,borderRight
,borderBottom
,borderTopColour
,borderLeftColour
,borderRightColour
,borderBottomColour
,borderDiagonal
,borderdiagonalColour
,borderDiagonalUp
,borderDiagonalDown
- [ ] simplify
bgFill
andfgFill
toc(back = ..., fore = ...)
(orbackground
andforgound
- [ ] simplify
halign
andvalign
toc(horizontal = "left", vertical = "top")
(h
andv
- [ ] create
- [ ] Is
wbStyle$as.list()
needed? Could we just useR6:::as.list.R6()
? Not sure there's much we're gaining
Pseuocode
Thinking about something like this:
wb_style(
font = wb_font_spec(),
borders = wb_border_spec(),
fill = wb_fill_spec(),
...
)
# specs are essentially custom classes that manage default values and checking
# these can then be applied to a worksheet cell range
# use "default" values, or getOptions()
wb_font_spec <- function(id, name, colour, family, scheme, decoration) {
# make some checks for clean up
...
# return as a wb_*_spec class
structure(
list(id, name, colour, family, scheme, decoration),
names = c("id", "name", "colour", "family", "scheme", "decoration")
class = "wb_font_spec"
)
}
wb_border_spec <- function(positions = "none", color = "none") {
# make some checks for clean up
...
# check for border positions
...
# return as a wb_*_spec class
structure(
list(id, name, colour, family, scheme, decoration),
names = c("id", "name", "colour", "family", "scheme", "decoration")
class = "wb_border_spec"
)
}
# these could be the same
wb_border_spec(positions = c("left", "right"), color = c("red", "black"))
wb_border_spec(positions = c("left", "right"), color = c(right = "black", left = "red"))
wb_border_spec(list(left = "red", right = "black"))