How to Read Excel Files in R with readxl
To read Excel files in R, the readxl package is the standard choice — it handles both .xls and .xlsx formats, requires no Java installation, and integrates with the tidyverse. A single call to read_excel() reads the first sheet by default.
library(readxl)
df <- read_excel("data.xlsx")
Read a specific sheet by name with sheet = "Sales" or by index with sheet = 2. List all sheet names before reading with excel_sheets(path). The col_names argument (default TRUE) treats the first row as column headers; set it to FALSE if your data starts on row one.
df <- read_excel("data.xlsx", sheet = "Sales",
col_types = c("text", "numeric", "date"))
For files with merged cells or complex formatting, openxlsx::read.xlsx() provides more control, while tidyxl::xlsx_cells() reads raw cell-level data including formatting metadata. For standard data tables in a single sheet, read_excel() handles everything in one call. You can also skip rows with the skip argument and set a maximum number of rows with n_max for previewing large workbooks.
See also
- How to Read a CSV File in R, Related data import
- How to Write a CSV File in R, Exporting data
- How to Write an Excel File in R, Writing Excel files