Home > OS >  Read open excel file in R
Read open excel file in R

Time:07-13

is there a way to read an open excel file into R?

When an excel file is open in Excel, Excel puts a lock on the file, such as the reading method in R cannot access the file.

Can you circumvent this lock?

Thanks

CodePudding user response:

What do you mean by "the reading method in R", and by "cannot access the file" (i.e. what code are you using and what error message do you get exactly)? I'm successfully importing Excel files that are currently open, with something like:

dat <- readxl::read_excel("PATH/TO/FILE.xlsx")

If the file is being edited in Excel, R will import the last saved version.

CodePudding user response:

I too do not have problem opening xlsx files that are already open in excel, but if you do i have a workaround that might work:

path_to_xlsx <- "C:/Some/Path/to/test.xlsx"
temp <- tempdir()
file.copy(path_to_xlsx, to = paste0(temp, "/test.xlsx"))
df <- openxlsx::read.xlsx(paste0(temp, "/test.xlsx"))

This copies the file (Which should not be blocked) to a temporary directory, and then loads the file from there. Again, i'm not sure if this is needed, as i do not have the problem you have.

  • Related