Search code examples
rcsvxlsr-rio

Convert XLS to CSV - R (Tried Rio Package)


I have a list of files in a directory which I'm trying to convert to csv, had tried rio package and solutions as suggested here

The output is list of empty CSV files with no content. It could be because the first 8 rows of the xls files have an image and few emtpy lines with couple couple of cells filled with text.

Is there any way I could skip those first 8 lines in all of xls files before converting.

Image of Input File. Couldn't add it as table since there is a picture embedded in first couple of rows of the xls files

Tried exploring options from openxlsx or readxls packages, any suggestions or guidance will be helpful.

Please do not mark as duplicate since I have a different problem than the one that was already answered


Solution

  • Although I was not able to do it with rio to convert, I read it as xls and wrote it back as csv using below code. Testing worked fine, Hope it works without glitch in implementation.

    files <- list.files(pattern = '*.xls')    
    
    y=NULL
    
    for(i in files ) {
      x <- read.xlsx(i, sheetIndex = 1, header=TRUE, startRow=9)
      y= rbind(y,x)
    }
    
    dt <- Sys.Date()
    fn<- paste("path/",dt,".csv",sep="")
    write.csv(y,fn,row.names = FALSE)