![](/img/trans.png)
[英]How to print top row in bold when writing dataframe to excel in R using write.xlsx
[英]R: How can you freeze the top row in an exported Excel file using R code?
解决方案必须在 R 中。相关问题正在为其他语言提供解决方案。 (例如,这里使用电子表格冻结顶行)
Excel 对应的
library(tidyverse)
mtcars %>% write_csv('IneedExcelNotCSV.csv')
部分代码冻结了顶行。
与 .xls(x) 类似的格式(例如,OpenOffice)的解决方案也可以。 (.sxc?)
如果您使用XLSX
R 包保存为 .xlsx 文件,您可以添加
createFreezePane(sheet, 2, 1, startRow = 2, startColumn = 1)
第一行被冻结。
使用openxlsx
包通过 freezePane 参数将数据导出为 .xlsx 文件时,您可以冻结窗格: firstActiveRow
、 firstActiveCol
、 firstRow
和firstCol
。
例如,要冻结第一行:
library(openxlsx)
write.xlsx(sheetname, file = filename, firstRow = TRUE) #freezes top row
write.xlsx(sheetname, file = filename, firstRow = TRUE, firstCol = TRUE) #freezes top row and first column
write.xlsx(sheetname, file = filename, firstActiveRow = 4, firstActiveCol = 3) #freezes fourth row and third column
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.