wb <- loadWorkbook("file.xlsx")
sheets <- getSheets(wb)
setColumnWidth(sheets[[1]], colIndex=1:ncol(df), colWidth=20)
saveWorkbook(wb,paste(Sys.Date(), "_abc.xlsx"))
如何在Excel中使用R将列名更改为粗体。
答案 0 :(得分:0)
您可以在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")
答案 1 :(得分:-1)
library(openxlsx)
my_data<-seq(1,12)
headerStyle <- createStyle(
textDecoration = "Bold"
)
writeData(wb, "A", my_data,)
addStyle(wb, sheet = 1, headerStyle, rows = 1, cols = 1:12, gridExpand = TRUE)
saveWorkbook(wb, "test.xlsx")