XLConnect cloneSheet错误

时间:2017-03-31 17:07:37

标签: r xlconnect

使用R(R 3.3),XLConnect包V 0.2.12,rJava包V 0.9.8,收到错误。

  

错误:IllegalArgumentException(Java):工作表索引(-1)超出范围(0..3)

当我运行clonesheet函数时。以下是工作簿的代码:

wb <- loadWorkbook(paste0("C:\\Users\\james.keane\\Documents\\R\\RETC R 
    Scripts\\Client Progress Report\\", fileName, separate = ""), create = 
    TRUE)
setStyleAction(wb,XLC$"STYLE_ACTION.NONE")        # This allows the 
     spreadsheet to be populated with data without chaninging the formating 
     of the spreadsheet

# Check to see if sheet exists
tabNames <- getSheets(wb)
if(length(grep(taxSeason, tabNames)) >= 1){
     writeWorksheet(wb, paste(taxSeason, "Property Tax Appeal Status", 
         separate = " "), sheet = taxSeason, startRow = 1, startCol = 1, 
         header = FALSE)
     writeWorksheet(wb, reportClient[,1:22], sheet = taxSeason, startRow = 
         3, startCol = 1, header = FALSE)
     writeWorksheet(wb, reportClient[,28:33], sheet = taxSeason, startRow = 
          3, startCol = 28, header = FALSE)
}else{
     cloneSheet(wb, "Template", taxSeason)
     writeWorksheet(wb, paste(taxSeason, "Property Tax Appeal Status", 
         separate = " "), sheet = taxSeason, startRow = 1, startCol = 1, 
         header = FALSE)
     writeWorksheet(wb, reportClient[,1:22], sheet = taxSeason, startRow = 
         3, startCol = 1, header = FALSE)
     writeWorksheet(wb, reportClient[,28:33], sheet = taxSeason, startRow = 
         3, startCol = 28, header = FALSE)
}
saveWorkbook(wb)

保存工作簿并打开文件后,我将有以下标签:image of tabs after code run

在代码运行之前,只有三个选项卡“Exhibit A”,“Template”和“Data Validation”。代码运行后,它应克隆模板选项卡,将其重命名为相应的taxSeason年份,然后使用writeWorkSheet函数填充此新工作表的数据。

曾经有一段时间它已经发挥了作用,有些时候并不那么不确定它为什么会来回走动。关于为什么会发生这种情况的任何想法?

0 个答案:

没有答案