0
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 中将列名称更改为粗体字体样式。

4

1 回答 1

3

您可以createStyleopenxlsx包装中使用。

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")
于 2019-03-19T22:50:59.527 回答