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

时间:2018-08-03 10:29:40

标签: openxlsx

将表格写入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”?

1 个答案:

答案 0 :(得分:0)

结果证明解决方案有点琐碎-使用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表的-与我所想的相反(通常只是写数据表)。