How to Write a Data Frame to an Excel File in R

· 1 min read · Updated March 15, 2026 · beginner
r excel data-export openxlsx writexl

There are several solid packages for writing Excel files from R. This cookbook covers the most reliable options.

With openxlsx

The openxlsx package gives you fine-grained control over Excel files:

library(openxlsx)
df <- data.frame(
  name = c("Alice", "Bob", "Carol"),
  score = c(85, 92, 78)
)
write.xlsx(df, "output.xlsx")

Create a workbook with multiple sheets:

wb <- createWorkbook()
addWorksheet(wb, "Sheet1")
writeData(wb, "Sheet1", df)
addWorksheet(wb, "Sheet2")
writeData(wb, "Sheet2", df * 1.1)
saveWorkbook(wb, "multi_sheet.xlsx", overwrite = TRUE)

With writexl

The writexl package is lightweight and fast:

library(writexl)
write_xlsx(df, "output.xlsx")

Write multiple data frames to different sheets:

write_xlsx(list(Students = df, Scores = df * 1.1), "combined.xlsx")

With xlsx package

The xlsx package uses Java but offers broad compatibility:

library(xlsx)
write.xlsx(df, "output.xlsx", sheetName = "Data")

See Also