问题
I have a folder of daily report in Excel XLSB format, now I am trying to import all files in the folder and bind into one data frame in R. I have experience with importing a folder of multiple CSV files into R, the code as below:
library(tidyverse)
setwd("C:/Folder_Path")
file_path <- list.files(pattern="*.csv")
combined_df <- lapply(file_path, read_csv) %>% bind_rows
I tried to implement this code into this case to import XLSB files, the spreadsheet I need is "Sheet1" and the header starts from row #4, therefore i created a custom function to do this:
library(tidyverse)
binary_import <- function(x){
readxl::read_excel(x, sheet="Sheet1", skip=3)}
setwd("C:/Folder_Path")
file_path <- list.files(pattern="*.csv")
combined_df <- lapply(file_path, binary_import) %>% bind_rows
Then i noticed that readxl package does not support xlsb extension. Is there any workarounds available for me to complete the job instead of manually converting the files into csv format because there are hundreds of files.
回答1:
Your code works except for the xlsb part. You could use excel.link package for reading xlsb
library(tidyverse)
library (excel.link)
setwd("C:/Folder_Path")
file_path <- list.files(pattern="*\\.xlsb")
allxlsb <- NULL
for(i in 1:length(file_path)){
temp <- xl.read.file(filename = file_path[i], xl.sheet = "Sheet1", top.left.cell = "A4")
allxlsb <- rbind(allxlsb, temp)
}
来源:https://stackoverflow.com/questions/48182490/import-folder-of-xlsb-files-into-r