Apply Excel Styling Across Multiple Spreadsheets using openxlsx in R?

I have an example where I write multiple individual spreadsheets, I would like to style each spreadsheet but expanding the column width, formatting it as a table, and making the header background blue:

Creation of Multiple Spreadsheets on Parameter Date

df <- data.frame(Date = Sys.Date() - 0:4, Logical = c(TRUE, FALSE, TRUE, TRUE, FALSE),
                 Currency = paste("$", -2:2), Accounting = -2:2, hLink = "https://CRAN.R-project.org/",
                 Percentage = seq(-1, 1, length.out = 5), TinyNumber = runif(5)/1e+09, stringsAsFactors = FALSE)

dat_grouped <- df %>% group_by(Date)


lapply(group_split(dat_grouped), function(x){openxlsx::write.xlsx(x, paste0(x$Date[1], ".xlsx"))})

How can I Apply Styling to Each Individual Spreadsheet – Example of Ideal Output

image

image

Where the header is light blue and columns are widened.

  • thanks, I reviewed the documentation and that part is clear but I am unsure how to apply the logic when I am sing lapply

    – 

  • 1

    Why not set up one workbook with all the formatting then use that as a template?

    – 

  • 1

    could you possibly share an example with the code and data I provided above please?

    – 

  • stackoverflow.com/questions/11228942/…

    – 

Leave a Comment