[R] RODBC to import/export xls files

Gabor Grothendieck ggrothendieck at gmail.com
Tue Feb 23 21:33:36 CET 2010


On Tue, Feb 23, 2010 at 1:45 PM, Henrique Dallazuanna <wwwhsd at gmail.com> wrote:
> see below:
>
> On Tue, Feb 23, 2010 at 2:16 PM, Ivan Calandra
> <ivan.calandra at uni-hamburg.de> wrote:
>> Dear R users,
>>
>> I've learned today about RODBC package in order to import xls file to
>> dataframes and export the dataframes to xls files.
>>
>> However I have some problems. Please excuse me if these are basic but as I
>> said, I've just begun with this package.
>> Also this email is quite long, but everything is related, so I don't think
>> it would be better to split it. Moreover, there's a lot from an error
>> message and dput(). I hope it won't discourage you. I believe I've
>> compressed it as much as possible
>>
>> - to import, I do this:
>> con <- odbcConnectExcel("D:\\R\\cdeg_SSFA_R.xls")
>> cdeg <- sqlFetch(con, "cdeg")
>
>  base <- sqlFetch(con, gsub("'|\\$", "", sqlTables(con)$TABLE_NAME[1]))

It seems to accept the $ so this is good enough if there is one sheet:

con <- odbcConnectExcel("test.xls")
sqlFetch(con, sqlTables(con)$TABLE_NAME)
close(con)

If there are multiple sheets sqlTables returns the sheets in
alphabetical order rather than the order in the workbook, at least
when I tried it using the ODBC driver that comes with Vista, so in
that case try one of the other solutions here:
http://rwiki.sciviews.org/doku.php?id=tips:data-io:ms_windows



More information about the R-help mailing list