I have a table I've created in R and am looking to output it to Excel using write.xlsx
but with all used cells bordered and centered. Can anyone help please, I gather I need to create a style and then apply that as part of the write.xlsx
command but am not sure how to do so.
Below code is the current write function which just exports without any formatting.
Thank you!
write.xlsx(FinalOutput, "//user017/userslocal/aaaa/Documents/R Experiments/FinalOutput1.xlsx")
CodePudding user response:
you can create an excel style with:
library(openxlsx)
custom_style <- openxlsx::createStyle(...)
And apply it to your excel file:
wb <- openxlsx::createWorkbook()
openxlsx::addWorksheet(wb, sheetName = "S1")
openxlsx::writeData(wb, FinalOutput)
openxlsx::addStyle(wb, S1, custom_style)
openxlsx::saveWorkbook(wb, "//user017/userslocal/aaaa/Documents/R Experiments/FinalOutput1.xlsx", overwrite = TRUE)