2

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.

m0nhawk
  • 22,980
  • 9
  • 45
  • 73
Felix Zhao
  • 459
  • 5
  • 9
  • Do you have `LibreOffice`? Someone mentioned you can use `soffice --convert-to csv *.xlsb` to convert all files to csv [Link](https://stackoverflow.com/q/45556974/786542) – Tung Jan 10 '18 at 08:26
  • 1
    mabye you find this helpful: https://stackoverflow.com/questions/28684199/how-to-open-an-xlsb-file-in-r – Antonios Jan 10 '18 at 09:35
  • Does this answer your question? [How to open an .xlsb file in R?](https://stackoverflow.com/questions/28684199/how-to-open-an-xlsb-file-in-r) – Rick Pack Aug 07 '20 at 12:49

1 Answers1

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)
}
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66