0
wb <- loadWorkbook("file.xlsx")   
sheets <- getSheets(wb)  
setColumnWidth(sheets[[1]], colIndex=1:ncol(df), colWidth=20)  
saveWorkbook(wb,paste(Sys.Date(), "_abc.xlsx"))

How do I change Column Names to Bold font style in Excel using R.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Anshuman
  • 39
  • 1
  • 5
  • 1
    Assuming you are using the `xlsx` package, create a `CellStyle()+Font(wb, isBold=TRUE)`, then apply it to the cells of the column names with `setCellStyle()`. – Bastien Mar 19 '19 at 08:07

1 Answers1

5

You can use createStyle in openxlsx package.

library(openxlsx)

# sample data
my_data <- data.frame(nam1 = 1:12, nam2 = month.abb, stringsAsFactors = FALSE)

# create workbook
wb <- createWorkbook()

# add Excel sheet
addWorksheet(wb, "A")

# create style, in this case bold header
header_st <- createStyle(textDecoration = "Bold")

# Write data with header style defined above
writeData(wb, "A", my_data, headerStyle = header_st)

# save to .xlsx file
saveWorkbook(wb, "test.xlsx")
MKa
  • 2,248
  • 16
  • 22