使用XLConnect读入xls

时间:2021-02-28 16:03:51

I'm using the following code to try and read in an old xls file

我正在使用以下代码尝试读取旧的xls文件

library("XLConnect")
path <- "C:/Users/foo/Desktop/WEEK 17.xls"
df <- readWorksheet(path, sheet = 1)

i get the following error

我收到以下错误

Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘readWorksheet’ for signature ‘"character", "numeric"’

(函数(classes,fdef,mtable)中的错误:无法为签名'“character”,“numeric”找到函数'readWorksheet'的继承方法

Does anyone know why? I can open the file in excel

有谁知道为什么?我可以在excel中打开文件

1 个解决方案

#1


3  

It s because readWorksheet use workbook as object.

这是因为readWorksheet使用工作簿作为对象。

You have to

你必须

# Load workbook
wb <- loadWorkbook("C:/Users/foo/Desktop/WEEK 17.xls")

and then

df <- readWorksheet(wb, sheet = 1)

or use readWorksheetFromFile("C:/Users/foo/Desktop/WEEK 17.xls", sheet = 1)

或者使用readWorksheetFromFile(“C:/ Users / foo / Desktop / WEEK 17.xls”,sheet = 1)

Which realy do the same

哪个真的做同样的事情

> XLConnect::readWorksheetFromFile
function (file, ...) 
{
    args <- list(...)
    args$object <- loadWorkbook(file, create = FALSE)
    do.call("readWorksheet", args)
}
<environment: namespace:XLConnect>

#1


3  

It s because readWorksheet use workbook as object.

这是因为readWorksheet使用工作簿作为对象。

You have to

你必须

# Load workbook
wb <- loadWorkbook("C:/Users/foo/Desktop/WEEK 17.xls")

and then

df <- readWorksheet(wb, sheet = 1)

or use readWorksheetFromFile("C:/Users/foo/Desktop/WEEK 17.xls", sheet = 1)

或者使用readWorksheetFromFile(“C:/ Users / foo / Desktop / WEEK 17.xls”,sheet = 1)

Which realy do the same

哪个真的做同样的事情

> XLConnect::readWorksheetFromFile
function (file, ...) 
{
    args <- list(...)
    args$object <- loadWorkbook(file, create = FALSE)
    do.call("readWorksheet", args)
}
<environment: namespace:XLConnect>