Read only certain columns from xls

前端 未结 3 1613
北海茫月
北海茫月 2021-01-06 10:59

I have an excel spreadsheet with several sheets. The format is as below:

Date        A       B       C       D       E       F                       Referenc         


        
相关标签:
3条回答
  • 2021-01-06 11:39

    You can use library XLConnect to read .xls files. Function readWorksheet() lets you set columns and rows you need to import.

    library(XLConnect)
    wb<-loadWorkbook("wb.xls")
    data <- readWorksheet(wb, sheet = "Sheet1",startCol=1,endCol=7)
    
    0 讨论(0)
  • 2021-01-06 11:48

    Another option is to use is to use Excel named range with RODBC.

    channel<-odbcConnectExcel(paste(Repository,excelFile, sep = "/"))
    ConsoTab<-sqlFetch(channel,NamesRangeAF)
    odbcClose(channel)
    

    Here NamesRangeAF is your Excel named Range.

    0 讨论(0)
  • 2021-01-06 12:03

    With the readxl package using read_xlsx you can specify the range. Use read_xls or read_excel depending on file type.

    library(readxl)
    df <- read_xlsx(path = "filename.xlsx", sheet = "sheetname", range = cell_cols("A:G"))
    
    0 讨论(0)
提交回复
热议问题