gpt4 book ai didi

r - 将数据导出到 Excel 工作表中的特定单元格

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

我需要将 R 中的数据框导出到 Excel 工作表,可以通过以下方式完成:

require("xlsx")
write.xlsx(x, file, sheetName="Sheet1", col.names=TRUE,
row.names=TRUE, append=FALSE, showNA=TRUE)

然后,我导出的数据将粘贴到 Excel 工作表的单元格“A1”中。我也可以设置 append=TRUE所以数据将被添加到工作表的末尾。

有没有可能把它放进 特定单元格 ?我需要将数据框导出到从单元格开始的范围 C10 .这可能吗?

更新:
工作表包含行 1-9 中的数据以及列 A-B .因此,不可能只将空单元格添加到数据框中并将其粘贴到 Excel 工作表中,因为这些空单元格会删除数据。

最佳答案

您可以使用包 XLConnect 来做到这一点。 .

library(XLConnect)
wb <- loadWorkbook("File_result.xlsx"), create = TRUE)
createSheet(wb, name = "Sheet1")

# here, you can set the startRow and startCol. Col A = 1, B = 2,...
writeWorksheet(wb,x,"Sheet1",startRow = 10, startCol = 3, header = TRUE)

# automatically adjust column width
setColumnWidth(wb, sheet = "Sheet1", column = 3:4, width = -1)
saveWorkbook(wb)

关于r - 将数据导出到 Excel 工作表中的特定单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29260914/

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