library(openxlsx)

my.wb <- createWorkbook() ## Create a new workbook
addWorksheet(wb=my.wb,    ## Add a worksheet
             sheetName = "Expenditure",
             gridLines = FALSE)

h.style <- createStyle( # create a style for column headers
  fontSize = 16, fontColour = "white", halign = "center",
  fgFill = "blue", border = "TopBottom", borderColour = "black"
)
tab.style <- createStyle( ## style for the body of the table
  border = "TopBottom", borderColour = "red")

## write data to worksheet 1
writeData(wb=my.wb, sheet = 1, x = USPersonalExpenditure, 
          colNames = TRUE, rowNames = TRUE,
          startRow = 4, startCol = 3, 
          headerStyle = h.style)

addStyle(wb=my.wb, sheet = 1, style = tab.style,
         rows = 5:(4+nrow(USPersonalExpenditure)),
         cols = 3:(3+ncol(USPersonalExpenditure)), 
         gridExpand = TRUE)
setColWidths(wb = my.wb, sheet = 1, ## set column width 
             cols = 3:(3+ncol(USPersonalExpenditure)),
             widths = "auto") 
saveWorkbook(wb=my.wb, file = "addStyleExample1.xlsx", 
             overwrite = TRUE)
## End(Not run)