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

create minimal dxfs styles #343

Closed
JanMarvin opened this issue Sep 26, 2022 · 0 comments
Closed

create minimal dxfs styles #343

JanMarvin opened this issue Sep 26, 2022 · 0 comments

Comments

@JanMarvin
Copy link
Owner

See ycphs/openxlsx#387 (comment)

> old <- create_dxfs_style(font_color = wb_colour(name = "black"), bgFill = wb_colour(hex = "FFBFBFBF"))
> new <- "<dxf><font/><fill><patternFill patternType=\"solid\"><bgColor rgb=\"FFBFBFBF\"/></patternFill></fill></dxf>"
> 
> old %>% as_xml()
<dxf>
 <font>
  <color rgb="FF000000" />
  <name val="Calibri" />
  <sz val="11" />
 </font>
 <fill>
  <patternFill patternType="solid">
   <bgColor rgb="FFBFBFBF" />
  </patternFill>
 </fill>
</dxf>
> new %>% as_xml()
<dxf>
 <font />
 <fill>
  <patternFill patternType="solid">
   <bgColor rgb="FFBFBFBF" />
  </patternFill>
 </fill>
</dxf>

Workaround

library(openxlsx2)

wb <- wb_workbook()$
  add_worksheet("Tab_1", zoom = 80, gridLines = FALSE)$
  add_worksheet("Tab_2", zoom = 80, gridLines = FALSE)

# ccs_gray <- create_dxfs_style(font_color = wb_colour(name = "black"), bgFill = wb_colour(hex = "FFBFBFBF"))
ccs_gray <- "<dxf><font/><fill><patternFill patternType=\"solid\"><bgColor rgb=\"FFBFBFBF\"/></patternFill></fill></dxf>"
wb$styles_mgr$add(ccs_gray, "ccs_gray")

wb <- wb_add_conditional_formatting(
  wb = wb,
  sheet = "Tab_1",
  cols = 1:5,
  rows = 1:10,
  rule = "MOD(ROW(A1), 2) = 0",
  style = "ccs_gray",
  type = "expression")

hl <- function(row = i) create_hyperlink(sheet = "Tab_2", row = i, col = 1, text = paste0("Link to 'Tab_2'"))

for(i in 1:10) {
  wb <- wb_add_formula(wb = wb, sheet = "Tab_1", startRow = i, startCol = 1, x = hl(i))
  for(j in 2:5) {
    wb <- wb_add_data(wb = wb, sheet = "Tab_1", x = "Some text", startRow = i, startCol = j)
  }
}

wb$open()
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

1 participant