Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

excel_format

Determine file format


Description

Determine if files are xls or xlsx (or from the xlsx family).

excel_format(guess = TRUE) is used by read_excel() to determine format. It draws on logic from two lower level functions:

  • format_from_ext() attempts to determine format from the file extension.

  • format_from_signature() consults the file signature or "magic number".

File extensions associated with xlsx vs. xls:

  • xlsx: .xlsx, .xlsm, .xltx, .xltm

  • xls: .xls

File signatures (in hexadecimal) for xlsx vs xls:

  • xlsx: First 4 bytes are 50 4B 03 04

  • xls: First 8 bytes are D0 CF 11 E0 A1 B1 1A E1

Usage

excel_format(path, guess = TRUE)

format_from_ext(path)

format_from_signature(path)

Arguments

path

Path to the xls/xlsx file.

guess

Logical. If the file extension is absent or not recognized, this controls whether we attempt to guess format based on the file signature or "magic number".

Value

Character vector with values "xlsx", "xls", or NA.

Examples

files <- c(
  "a.xlsx",
  "b.xls",
  "c.png",
  file.path(R.home("doc"), "html", "logo.jpg"),
  readxl_example("clippy.xlsx"),
  readxl_example("deaths.xls")
)
excel_format(files)

readxl

Read Excel Files

v1.3.1
GPL-3
Authors
Hadley Wickham [aut] (<https://orcid.org/0000-0003-4757-117X>), Jennifer Bryan [aut, cre] (<https://orcid.org/0000-0002-6983-2759>), RStudio [cph, fnd] (Copyright holder of all R code and all C/C++ code without explicit copyright attribution), Marcin Kalicinski [ctb, cph] (Author of included RapidXML code), Komarov Valery [ctb, cph] (Author of included libxls code), Christophe Leitienne [ctb, cph] (Author of included libxls code), Bob Colbert [ctb, cph] (Author of included libxls code), David Hoerl [ctb, cph] (Author of included libxls code), Evan Miller [ctb, cph] (Author of included libxls code)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.