Save Excel spreadsheet as .csv with R?

后端 未结 3 1706
星月不相逢
星月不相逢 2021-02-15 11:27

What is the simplest way to convert a large Excel spreadsheet with multiple worksheets into .CSV files in R?

Note that I\'ve tested XLConnect and XLSX and found that m

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-15 11:53

    Here's a loop to write out all sheets:

    require(gdata)
    ## install support for xlsx files
    installXLSXsupport()
    excelFile <- ("/full/path/to/excelFile.xlsx")
    ## note that the perl scripts that gdata uses do not cope well will tilde expansion
    ## on *nix machines. So use the full path. 
    numSheets <- sheetCount(excelFile, verbose=TRUE)
    
    for ( i in 1:numSheets) {
      mySheet <- read.xls(excelFile, sheet=i)
      write.csv(mySheet, file=paste(i, "csv", sep="."), row.names=FALSE)
    }
    

提交回复
热议问题