简体   繁体   English

如何在R中使用XLConnect读取.xlsx文件

[英]How to read .xlsx file using XLConnect in R

I want to read an .xls or .xlsx file from my hard drive using R. I installed the XLConnect package and have received the following errors: 我想使用R从硬盘驱动器中读取.xls或.xlsx文件。我安装了XLConnect软件包,并收到以下错误:

Data <- readWorksheet(loadWorkbook("C:/test1.xlsx"),sheet=1)
Error: FileNotFoundException (Java): File 'test1.xlsx' could not be found - you may specify to automatically create the file if not existing.

I want to read the first tab of my Excel file. 我想阅读Excel文件的第一个标签。 I also tried the gdata read.xls function and failed. 我还尝试了gdata read.xls函数,但失败了。

Try to define your working directory before calling the xlsx file. 在调用xlsx文件之前,尝试定义工作目录。 So use the function setwd before calling the file. 因此,在调用文件之前,请使用函数setwd。 Example: 例:

setwd("the location where the file is placed on your pc")
Data <- readWorksheet(loadWorkbook("C:/test1.xlsx"),sheet=1)

Note: make sure u are using forward slashes instead of backwards slashes in the setwd function. 注意:确保在setwd函数中使用正斜杠而不是反斜杠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM