gpt4 book ai didi

openxlsx - 防止 writeDataTable (openxlsx) 写入任何列名

转载 作者:行者123 更新时间:2023-12-04 13:44:20 26 4
gpt4 key购买 nike

将表格写入 Excel 工作簿时:

wb <- createWorkbook()
addWorksheet(wb, "Data")
data <- tibble(x = seq(1,10), y = c("A","B","C","D", NA, NA, NA, NA, NA, NA))
writeDataTable(wb, sheet = "Data", x = data, colNames = FALSE, withFilter = FALSE, tableStyle = "none")
saveWorkbook(wb, file = "Temp.xlsx", overwrite = TRUE)

即使 colNames = FALSE,名称也会被写入 - 只是实际的列名被“Column1”、“Column2”等替换了。

有没有办法让 writeDataTable 写入表并完全省略列名 - 以便 data.frame 中的第一个数据值写入 A1(或指定的任何地方),而不是“Column1”?

最佳答案

事实证明解决方案有点简单 - 使用 writeData 而不是 writeDataTable

wb <- createWorkbook()
addWorksheet(wb, "Data")
data <- tibble(x = seq(1,10), y = c("A","B","C","D", NA, NA, NA, NA, NA, NA))
writeData(wb, sheet = "Data", x = data, colNames = FALSE, withFilter = FALSE, tableStyle = "none")
saveWorkbook(wb, file = "Temp.xlsx", overwrite = TRUE)

我没有意识到 writeDataTable 函数是专门用于编写 Excel 表格的 - 与我的想法相反(通常只是编写数据表格)。

关于openxlsx - 防止 writeDataTable (openxlsx) 写入任何列名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51670672/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com