我正在尝试使用 RODBC 写入 Excel2007 文件,但我不断收到错误消息。我已将问题简化为这个非常基本的情况,即具有字符、数字、日期和逻辑数据类型的 1 行 data.frame:
toWrite = data.frame( Name = "joe" , Date = as.Date("2011-01-01"), Value = 2 , Paid = FALSE )
xlFile = odbcConnectExcel2007( "REPLACE_WITH_XLSB_FILE_PATH" , readOnly = FALSE )
sqlSave( xlFile , toWrite , tablename = "worksheet1" , rownames = FALSE )
错误:
Error in sqlSave(xlFile, toWrite, tablename = "worksheet1", rownames = FALSE) :
[RODBC] Failed exec in Update
22018 39 [Microsoft][ODBC Excel Driver]Invalid character value for cast specification
In addition: Warning message:
In odbcUpdate(channel, query, mydata, coldata[m, ], test = test, :
character data 'FALSE' truncated to 1 bytes in column 'Paid'
如果我将日期和逻辑列都转换为字符,那么一切正常。问题是这些现在是 Excel 中的字符,并且不能在没有转换的情况下用作预期的数据类型。我深入研究了 sqlSave 代码,它似乎在做正确的事情。有没有其他人遇到过这个问题?