Color list of dataframes before exporting to excel

Styles aren’t possible with CSV output. If you output to xlsx, you can set styles using openxlsx.

library(openxlsx)

wb <- createWorkbook()
addWorksheet(wb, "Iris")
writeDataTable(wb, "Iris", iris, tableStyle = "TableStyleMedium2")
saveWorkbook(wb, "iris.xlsx", overwrite = TRUE)

excel

Here’s the code for your example.

library(openxlsx)

save_data <- function(df, name) {
  wb <- createWorkbook()
  addWorksheet(wb, name)
  writeDataTable(wb, name, df, tableStyle = "TableStyleMedium2")
  saveWorkbook(wb, paste0(name, ".xlsx"), overwrite = TRUE)
}

mapply(
  save_data,
  splitdf,
  names(splitdf)
)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top