3

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

4

1 回答 1

0

原来解决方案有点琐碎 - 使用writeDatanot 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 表格 - 与我的想法相反(通常只是编写数据表格)。

于 2018-08-03T10:41:01.663 回答