通过 RODBC 连接到 Excel 文件

虽然 RODBC 仅限于在 R 和任何目标 RDMS 之间具有兼容架构的 Windows 计算机,但其关键灵活性之一是使用 Excel 文件,就像它们是 SQL 数据库一样。

require(RODBC)
con = odbcConnectExcel("myfile.xlsx") # open a connection to the Excel file
sqlTables(con)$TABLE_NAME # show all sheets
df = sqlFetch(con, "Sheet1") # read a sheet
df = sqlQuery(con, "select * from [Sheet1 $]") # read a sheet (alternative SQL syntax)
close(con) # close the connection to the file