繁体   English   中英

R:如何使用 R 代码冻结导出的 Excel 文件的第一行?

[英]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 文件时,您可以冻结窗格: firstActiveRowfirstActiveColfirstRowfirstCol

例如,要冻结第一行:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM