Skip to content
Prev 302816 / 398503 Next

Saving Splitted Series to Excel via XLConnect

Dear Rui and David,

Thanks a lot for your help and advices. Now finally I have
what I want ;-) The final code looks like this:

<R code begin>

dados <- data.frame(matrix(c("2012-01-01","2012-02-01",
  "2012-03-01","2012-04-01","2012-05-01","2012-06-01",
  "2012-01-01","2012-02-01","2012-03-01","2012-04-01",
  "2012-05-01","2012-06-01","2012-01-01","2012-02-01",
  "2012-03-01","2012-04-01","2012-05-01","2012-06-01",
  0.56,0.45,0.21,0.64,0.36,0.08,152136,153081,155872,
  158356,162157,166226,33.47,34.48,35.24,38.42,35.33,
  34.43,433,433,433,433,433,433,2005,2005,2005,2005,
  2005,2005,3939,3939,3939,3939,3939,3939),nrow=18,
  ncol=3,byrow=FALSE,dimnames=list(c(1,2,3,4,5,6,7,8,9,
  10,11,12,13,14,15,16,17,18),c("date","value","code"))))

dados2 <- split(dados, dados$code)

library(XLConnect)

wb <- loadWorkbook("Henrique.xlsx", create = TRUE)
series <- seq_along(dados2)
createSheet(wb, name = "Planilha")

lapply(series, function(i){
	column <- (3*i) - 2
	writeWorksheet(wb, dados2[[i]], sheet = "Planilha",
        startCol = column)})
saveWorkbook(wb)

<R code end>

I did not use the option to build a new sheet for each "i"
because I have more than 200 objects in my real problem.

Again, many thanks to you guys!

Best regards (or "Um abra?o"),
Henrique Andrade


2012/8/8 Rui Barradas <ruipbarradas at sapo.pt>: