wb <- loadWorkbook("file.xlsx")
sheets <- getSheets(wb)
setColumnWidth(sheets[[1]], colIndex=1:ncol(df), colWidth=20)
saveWorkbook(wb,paste(Sys.Date(), "_abc.xlsx"))
如何使用 R 在 Excel 中将列名称更改为粗体字体样式。
您可以createStyle
在openxlsx
包装中使用。
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")