R脚本RDCOMClient可以';t打开xlsx文件

R脚本RDCOMClient可以';t打开xlsx文件,r,excel,xlsx,rdcomclient,R,Excel,Xlsx,Rdcomclient,我正在尝试将在R中组织的重要数据组织到现有工作簿(xlsx文件)的现有表中。数据整理完成后,我有以下代码: file <- "U:/Reporting/Template-Business_Report.xlsx" xlApp <- COMCreate("Excel.Application") xlWbk <- xlApp$Workbooks()$Open(Filename = file) Sys.sleep(1) sheet <-

我正在尝试将在R中组织的重要数据组织到现有工作簿(xlsx文件)的现有表中。数据整理完成后,我有以下代码:

file <- "U:/Reporting/Template-Business_Report.xlsx"

xlApp <- COMCreate("Excel.Application")
xlWbk <- xlApp$Workbooks()$Open(Filename = file)
Sys.sleep(1)
sheet <- xlWbk$Worksheets("DataSet")
range <- sheet$Range("Table1")
range[["Value"]] <- asCOMArray(table)
newfile <- paste(sub("Template", state, file),format(Sys.time(), format = "%y%m%d %H%M"))


xlWbk$Save()                  # save the workbook
xlWbk$SaveAS(Filename =asCOMArray(newfile))  # save as a new workbook
xlApp$Quit()
该文件存在,但无法工作。我想知道它是否是打开的(在后台),这就是它抛出错误的原因,但它也不允许我关闭它

我还尝试:

file <- "U:\\Template-Business_Report.xlsx"
file <- "Template-Business_Report.xlsx"

为什么RDCOMClient找不到我的文件

file <- "U:\\Template-Business_Report.xlsx"
file <- "Template-Business_Report.xlsx"

xlWbk <- xlApp$Workbooks()$Open(Filename = file , 0, TRUE)