Excel 电子表格可以导入到 Excel ODBC 接口通过使用 rxImport XDF 文件中。假设 Excel ODBC 驱动程序安装和配置在 Windows 上,导入工作表"Sheet1"的工作簿"C:/Data/ODBCTest.xlsx"就是代码的示例︰
#Define ODBC connection string.connectionStr <- "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DriverId=790;Dbq=C:/Data/ODBCTest.xlsx;DefaultDir=c:/Data;"
#Define ODBC query into workbook. The worksheet name must be followed by '$' and enclosed in [].
testExcel = "SELECT * FROM [Sheet1$]"
#Define ODBC data source for the import using the query and connection string.
excelDS<- RxOdbcData(sqlQuery = testExcel, connectionString=connectionStr)
#Define input workbook and output xdf file.
excelDS_XDF<- RxXdfData("testFromExcel.xdf")
#Import the workbook into the XDF
rxImport(excelDS, excelDS_XDF, overwrite=TRUE)