Merging different Excel sheets with same column heeadings

Hi
I have about 25 Excel file consisting of 25 sheets. All the sheets have samee column headings. I want to get a file which merges all the data from the sheets into a single sheet. Is it possible to do it?

Yes, this can be done. Here is an example of reading in all of the xlsx files in a given directory and merging the two sheets in each file and the content of all of the files into a single data frame.

library(openxlsx)
library(purrr)
FILES <- list.files("~/R/Play", "xlsx$")
ReadSheets <- function(Nm) {
  map_dfr(1:2, ~read.xlsx(Nm, sheet = .x))
}
Out <- map_dfr(FILES, ReadSheets)

If all of your files are in one directory and they are the only xlsx files in that directory and they all have 25 sheets, that code should work if you set the correct directory path and change the 1:2 to 1:25.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.