Last active
November 13, 2023 14:56
-
-
Save matt-dray/3910663e0c7cbf499d65ee3a73efcb88 to your computer and use it in GitHub Desktop.
A test of how automatic font colour is handled in {openxlsx} (it isn't) and {openxlsx2} (it is)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(openxlsx) | |
font_name <- "Comic Sans MS" | |
sheet_name <- "font_test" | |
font_null <- createStyle(fontName = font_name) | |
font_black <- createStyle(fontName = font_name, fontColour = "black") | |
font_red <- createStyle(fontName = font_name, fontColour = "red") | |
row_seq <- 1:nrow(beaver1) | |
wb_openxlsx <- createWorkbook() | |
addWorksheet(wb_openxlsx, sheet_name) | |
writeDataTable(wb_openxlsx, 1, beaver1) | |
addStyle(wb_openxlsx, 1, font_null, cols = 2, rows = row_seq) | |
addStyle(wb_openxlsx, 1, font_black, cols = 3, rows = row_seq) | |
addStyle(wb_openxlsx, 1, font_red, cols = 4, rows = row_seq) | |
openXL(wb_openxlsx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(openxlsx2) | |
font_name <- "Comic Sans MS" | |
sheet_name <- "font_test" | |
wb_openxlsx2 <- wb_workbook() |> | |
wb_add_worksheet(sheet_name) |> | |
wb_add_data_table(sheet_name, beaver1) |> | |
wb_add_font( | |
sheet = sheet_name, | |
dims = paste0("A1:A", nrow(beaver1)), | |
name = font_name, | |
color = wb_color(auto = "1") | |
) | |
wb_open(wb_openxlsx2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment