Troubles with createSheet

391 views
Skip to first unread message

PaulineV

unread,
Oct 27, 2015, 11:31:11 AM10/27/15
to R-package-xlsx
Hello xlsx community,
I'm having troubles for the first time with a xlsx function. I'm trying to create dataframe from a loop, insert them in a sheet and then, save the workbook.
Here is a little example :

for(u in 1:dim(mydata)[2]){
        onglet3=createSheet(wb=wb2,sheetName=paste("Tri",u,sep=""))
        onglet4=createSheet(wb=wb2,sheetName=paste("Triproba",u,sep=""))
        a=resultatstries(colnames(chargeplan()$ua1)[u])
        b=a$resultats
        d=a$resultats2
        addDataFrame(x=b, sheet=onglet3,startRow=1,startColumn = 1,row.names = FALSE,col.names = FALSE)
        addDataFrame(x=d, sheet=onglet4,startRow=1,startColumn = 1,row.names = FALSE,col.names = FALSE)

       ### some test in order to colour cells from onglet3 according to values in onglet4
       ### Object d goes in another file and I remove the sheet named "Triproba" from wb2 beacuse I don't need it (and I don't want it to appear on the final results file
        write.xlsx(d,file=paste(file2,nom2, sep=""),sheetName = paste("Proba tri",u,sep=""),append=TRUE)  
        removeSheet(wb2,paste("Triproba",u))
        }

For now, mydata have 2 columns. It works for u=1 and then, for u=2, I get at the first line : Error in .jcall(wb, "Lorg/apache/poi/ss/usermodel/Sheet;", "createSheet",  : 
  java.lang.IllegalArgumentException: Sheet index (-1) is out of range (0..5)

I've been searching for hours in the Internet without finding any solution.

Would be so great to have a little help :)

Thank you very much in advance,

Pauline

Adrian Dragulescu

unread,
Oct 27, 2015, 11:34:53 AM10/27/15
to R-package-xlsx

User error.  The sheet you are trying to remove does not exist.  You forgot sep="" in paste.

Adrian

> --
> You received this message because you are subscribed to the Google Groups "R-package-xlsx" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to r-package-xls...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages