0

With R and xlsx, I know I can format the cell style using the following:

 STYLE <- CellStyle(wb) + Font(wb, heightInPoints = 14, name = "Arial")
 setCellStyle(cells[[2,2]], STYLE)

However, I would like the entire sheet to be of this format. I don't think I should be looping every cell to achieve this.

Is this a way to specific that only that sheet has this format?

Thanks for help folks

delita
  • 1,571
  • 1
  • 19
  • 25
  • please consider using `openxlsx` for dealing with xlsx-files inside R. – Andre Elrico Aug 29 '18 at 07:17
  • Possible duplicate of [Formatting an entire excel workbook efficiently using the R xlsx package](https://stackoverflow.com/questions/38871931/formatting-an-entire-excel-workbook-efficiently-using-the-r-xlsx-package) – KoenV Aug 29 '18 at 07:24

1 Answers1

0

If you are interested in using a "good" xlsx-package named openxlsx.

styler <- openxlsx::createStyle(fontName = "Arial", fontSize = 14, border = "top")

wb<-openxlsx::createWorkbook()
openxlsx::addWorksheet(wb,sheetName = "newSheet")
openxlsx::addStyle(wb,"newSheet",styler,0:nrow(mtcars)+1,1:ncol(mtcars),T,F)
openxlsx::writeData(wb,"newSheet",mtcars)
openxlsx::saveWorkbook(wb,"SO_test.xlsx",T)

Please note:

I have added a border to the style just to enforce my point that you can style the way you like it. Remove it at any time.

Andre Elrico
  • 10,956
  • 6
  • 50
  • 69