我是一名初学者,正在尝试将RStudio中的数据框插入到现有的Excel表格中,而不会丢失该表格中的先前数据或覆盖整个文件。例如,在第16行,第1列的Sheet“August”中插入新的数据框(15行,4列)到文件“Reporting.xlsx”中,以便先前的信息不会丢失?谢谢!
类似这样:
library(openxlsx)
library(dplyr)
# Get existing data and append new data
dat = readWorkbook("Reporting.xlsx", sheet="August")
dat = bind_rows(dat, new_data_frame)
# Write updated data frame to existing worksheet
wb = loadWorkbook("Reporting.xlsx")
writeData(wb, "August", dat)
# Save file (with new name for testing purposes)
saveWorkbook(wb, "Reporting_test.xlsx")
# To overwrite the pre-existing data file, you can do the following (commented out for safety)
#saveWorkbook(wb, "Reporting.xlsx", overwrite=TRUE)