openxlsx2 icon indicating copy to clipboard operation
openxlsx2 copied to clipboard

`wbStyle` enchancements

Open jmbarbone opened this issue 3 years ago • 0 comments

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 including fontId, fontName, fontColour, fontSize, fontFamily, fontScheme, fontDecoration
  • [ ] create wb_border_specs() to simplify including borderTop, borderLeft, borderRight, borderBottom, borderTopColour, borderLeftColour, borderRightColour, borderBottomColour, borderDiagonal, borderdiagonalColour, borderDiagonalUp, borderDiagonalDown
  • [ ] simplify bgFill and fgFill to c(back = ..., fore = ...) (or background and forgound
  • [ ] simplify halign and valign to c(horizontal = "left", vertical = "top") (h and v
  • [ ] create
  • [ ] Is wbStyle$as.list() needed? Could we just use R6:::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"))

jmbarbone avatar Feb 05 '22 17:02 jmbarbone