简体   繁体   English

将数据框从R导出到Excel,同时在excel文件上保留旧数据

[英]Export dataframe from R to Excel, while preserving old data on excel file

I'm using the write.xlsx command to export my dataframe in R to excel. 我正在使用write.xlsx命令将R中的数据框导出到excel。 eg write.xlsx(output, "C:/myfolder/output.xlsx) The dataframe has 4 columns. The data in these columns gets updated weekly. I want to export the dataframe in R to an excel file without losing the old data I had from the previous week. 例如write.xlsx(output, "C:/myfolder/output.xlsx)数据write.xlsx(output, "C:/myfolder/output.xlsx)有4列。这些列中的数据每周更新一次。我想将R中的数据框导出到excel文件,而又不会丢失旧数据I从前一周开始。

Basically, exporting the data to an excel file should help keep a log of the data week on week 基本上,将数据导出到excel文件应有助于每周保持数据日志

You can write each week's data to a separate worksheet within the same workbook using XLConnect package. 您可以使用XLConnect包将每周的数据写入同一工作簿中的单独工作表。

library(XLConnect)
dat <- loadWorkbook(filename="yourDataFile.xlsx") # read existing file
createSheet(dat, name = "weekNumber") # create worksheet for the current week
writeWorksheet(dat,
               sheet = "weekNumber",
               data = yourDataframe,
               header = FALSE,
               rownames = NULL) # write yourDataframe to the new worksheet
saveWorkbook(dat) # save the new worksheet

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM