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

Prevent writeDataTable (openxlsx) from writing any column names

将 table 写入 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 写入 table 并完全省略列名 - 以便 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 表 - 与我的想法相反(通常只是编写数据表)。