【问题标题】:How to change Column Names to Bold font style in Excel如何在 Excel 中将列名称更改为粗体字体样式
【发布时间】:2019-03-19 07:51:43
【问题描述】:
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 将列名称更改为粗体样式。

【问题讨论】:

  • 假设您使用的是xlsx 包,创建一个CellStyle()+Font(wb, isBold=TRUE),然后将其应用于具有setCellStyle() 的列名称的单元格。

标签: r excel xlsx openxlsx


【解决方案1】:

您可以在openxlsx 包中使用createStyle

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-10-08
    • 1970-01-01
    • 2011-06-02
    • 2012-10-10
    • 2015-09-23
    • 2017-04-27
    • 1970-01-01
    • 1970-01-01
    • 2019-04-01
    相关资源
    最近更新 更多