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