The fastest way to read every sheet of an Excel workbook in R is to use the readxl package: call excel_sheets("file.xlsx") to get a character vector of sheet names, then pass that vector to lapply() with read_excel() as the function. The result is a named list of data frames, one per sheet, which you can then combine with dplyr::bind_rows() or work on individually. This guide walks through that workflow, plus the variants you need when sheets have different structures, when you want each sheet as a separate object, and when readxl is not the right tool at all.
What You'll Need
- R installed, and preferably RStudio (the same code works in any IDE or the plain console).
- The
readxlpackage, installed once withinstall.packages("readxl"). - The
dplyrpackage if you plan to stack or reshape sheets; install withinstall.packages("dplyr"). - An Excel file saved on disk, with the path to it. Prefer
.xlsxover the older.xlswhere you have the choice, since both are supported but.xlsxis more predictable. - Knowledge of which sheets you actually need. A workbook with hidden sheets or leftover scratch tabs will otherwise silently add junk frames to your list.
Step-by-Step
- Load the library. Run
library(readxl). If you get "there is no package called 'readxl'", install it first and load it again. - Confirm the file path. Store it in a variable so you only type it once:
path <- "data/report.xlsx". Use forward slashes even on Windows, or double backslashes. If R cannot find the file, see the troubleshooting section; this is the single most common failure. - List the sheet names. Run
sheets <- excel_sheets(path). Printsheetsto the console and check it against what you expect. This step also proves the file opens and is readable before you attempt any parsing. - Read all sheets into a list. Run
all_sheets <- lapply(sheets, read_excel, path = path). Note the argument order:lapplypasses each sheet name as the first argument toread_excel, which is thesheetargument, andpathis supplied by name. The result is an unnamed list the same length assheets. - Name the list elements. Add names so you can address sheets by name rather than by position:
names(all_sheets) <- sheets. Nowall_sheets[["Q1"]]gives you the first-quarter sheet directly, andnames(all_sheets)reminds you what is inside. - Inspect one or two frames. Run
str(all_sheets[[1]])orglimpse(all_sheets[[1]])ifdplyris loaded. Check that column types look right; a column of numbers that came in as character usually means stray text or a total row in that sheet. - Stack the sheets if they share a structure. Load
dplyrand runcombined <- bind_rows(all_sheets, .id = "sheet"). The.idargument adds a column recording which sheet each row came from, which is invaluable later.bind_rowsmatches columns by name, so a sheet missing a column getsNArather than an error. - Or keep them separate. If sheets are genuinely different tables (for example a customer list and a monthly summary), do not stack them. Assign them to individual objects with
list2env()only if you really want separate variables, but keeping them in a list is usually cleaner because loops andlapplycan process all of them in one go. - Read a specific sheet by name. When you only need some sheets, skip the full sweep:
read_excel(path, sheet = "Summary"). This is faster and avoids type conflicts between sheets thatbind_rowswould otherwise complain about. - Read a specific sheet by position. Sheet numbers count from 1 in reading order.
read_excel(path, sheet = 3)reads the third tab. Position is fragile, since inserting a tab anywhere earlier shifts every index, so prefer names in scripts you will run again. - Handle header and range variations. If a sheet has a title row or blank rows above the real header, use
skipandrange. For exampleread_excel(path, sheet = "Data", skip = 3)ignores the first three rows, andrange = "B4:G200"reads only that rectangle. You can pass these throughlapplywith an anonymous function:lapply(sheets, function(s) read_excel(path, sheet = s, skip = 2)). - Save the result. Write the combined frame out with
write.csv(combined, "combined.csv", row.names = FALSE)if you need a portable file, or keep it in the session for analysis. Confirm the row count of the combined frame roughly equals the sum of the individual sheets.
Common Mistakes
Passing the path as the first lapply argument. lapply(sheets, read_excel, path) without naming path will fail, because the path lands in the sheet slot. Always write path = path.
Assuming the list is named. lapply over an unnamed vector returns an unnamed list. Without the names() assignment or .id in bind_rows, you lose track of which frame is which sheet.
Stacking sheets that differ in structure. bind_rows will happily glue a transactions sheet to a summary sheet, producing a wide, half-empty mess. Check the column names of each sheet before combining.
Column type mismatches. bind_rows errors when the same column is numeric in one sheet and character in another. Inspect the frames and fix the offending sheet, or read everything as text with col_types = "text" and convert afterwards.
Including hidden or metadata sheets. These often have only a cell or two of content and will break parsing. Filter the sheet vector before reading: sheets <- setdiff(sheets, "Notes").
Forgetting that read_excel guesses types from the first rows. Long files with an early block of text in a numeric column can come through as character. Supply col_types explicitly for important imports.
Using read.xlsx from the openxlsx package with readxl conventions. The two packages look similar but openxlsx takes sheet names or indices in its own way and does not have excel_sheets. Pick one package and stay consistent.
Tips
Wrap the whole pattern in a small function so every import is identical: a function that takes a path, lists sheets, reads them, and returns a named list. That removes variation between scripts and makes debugging much faster.
Use purrr::map() instead of lapply() if you are already in the tidyverse: map(all_sheets, ~ nrow(.x)) reads a little more naturally, and map_dfr() can combine frames in one call.
Add a quick quality check after reading: sapply(all_sheets, nrow) shows rows per sheet, and a zero often reveals a sheet that parsed only a header. Similarly, sapply(all_sheets, ncol) catches sheets pulled in with the wrong range.
Keep the original file open in a spreadsheet program only when you are not running the import. Excel locks files on some systems, and readxl can then throw an error that looks like a parsing problem.
Prefer .xlsx. If a vendor sends .xls, readxl handles it, but formulas stored without cached values can come through as blank cells, so verify a couple of computed columns.
Troubleshooting
"Path does not exist." Print getwd() and compare with the folder holding your file. Either set the working directory with setwd() or, better, use a full path or an RStudio project. Check the extension is spelled correctly and that Excel has not hidden it, so the real name is not report.xlsx.xlsx.
"File is not a zip file" or similar parse errors. The file may be an older .xls saved with an .xlsx extension, a password-protected workbook, or a partial download. Open it manually in a spreadsheet program to confirm it is intact, and re-export if necessary.
Wrong columns or garbage headers. Usually merged header cells or a title row. Inspect the first rows by reading with col_names = FALSE and n_max = 10, then set skip and range to match.
Sheets read but with the wrong data type. Identify the column and pass col_types, for example col_types = c("text", "numeric", "date", "skip"), with skip dropping a column entirely. A single space in one cell is enough to turn a whole numeric column into text.
Memory pressure on large workbooks. Read sheets one at a time in a loop and keep only what you need rather than holding everything at once. If the file is very large, ask whether a CSV export would be easier to work with.
If that did not work: read the file interactively with Excel in RStudio's import dialog to see exactly what the parser sees, then reproduce those settings in code. If readxl still fails, openxlsx is a legitimate alternative and sometimes copes with files readxl rejects.
Frequently Asked Questions
Can I read every sheet in one call without a loop?
Not directly. read_excel takes a single sheet per call, so you need lapply, purrr::map or an equivalent. lapply over excel_sheets() is the concise standard pattern.
How do I know how many sheets a workbook has?
length(excel_sheets(path)) gives the count, and printing the vector shows the names, which is more useful than the number.
Do I need Java for this?
No. readxl has no Java dependency, which is exactly why it is preferred over older packages such as xlsx that require a Java installation.
Can I read only certain columns or rows from every sheet?
Yes. Pass range in the same lapply call, or use col_types = "skip" to drop unwanted columns while keeping the rest.
What is the difference between the sheet name and the sheet index?
The name is the tab label you see in Excel; the index is its position counting from 1. Names survive tabs being reordered, so they are the safer choice in saved scripts.
Can I combine sheets that have different columns?
You can, and bind_rows will pad missing columns with NA. Whether you should is a separate question; if the sheets describe different things, keep them in a list and analyse them separately.