Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Importing .xlsx files using rxImport()


View products that this article applies to.

Problem

Is there a way to import .xlsx Excel files using rxImport(). rxImport() has ODBC functionality.

↑ Back to the top


Solution

This may be possible if you can setup the proper ODBC connection string and express a correct query but it has not been tested. I will need to investigate whether this is supported. Are you able to verify you can connect to and query the Excel spreadsheet via ODBC outside of R? Can you provide the entire script you are trying to run as well as what version of Excel you are running.

If this will not work with rxImport, an alternative would be the RODBC package which does have more direct Excel/ODBC support. This would bring the Excel spreadsheet into a data frame which could then be written to an XDF file.

Here is a short general example for importing an Excel workbook into an .xdf file:

sConnectionStr <- "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DriverId=790;Dbq=C:/Data/ODBCTest.xlsx;DefaultDir=c:/Data;" 
testExcel = "SELECT * FROM [Sheet1$]" 
excelDS<- RxOdbcData(sqlQuery = testExcel, connectionString=sConnectionStr) 
excelDS_XDF<- RxXdfData("testFromExcel.xdf") 
rxImport(excelDS, excelDS_XDF, overwrite=TRUE)

↑ Back to the top


Keywords: kb

↑ Back to the top

Article Info
Article ID : 3103839
Revision : 1
Created on : 1/7/2017
Published on : 11/1/2015
Exists online : False
Views : 66