Skip to contents

Return the date origin used internally by an xlsx or xlsm file

Usage

get_date_origin(xlsxFile, origin = FALSE)

Arguments

xlsxFile

An xlsx or xlsm file or a wbWorkbook object.

origin

return the origin instead of the character string.

Value

One of "1900-01-01" or "1904-01-01".

Details

Excel stores dates as the number of days from either 1904-01-01 or 1900-01-01. This function checks the date origin being used in an Excel file and returns is so it can be used in convert_date()

See also

Examples


## create a file with some dates
temp <- temp_xlsx()
write_xlsx(as.Date("2015-01-10") - (0:4), file = temp)
m <- read_xlsx(temp)

## convert to dates
do <- get_date_origin(system.file("extdata", "openxlsx2_example.xlsx", package = "openxlsx2"))
convert_date(m[[1]], do)
#> [1] "1945-01-07" "1945-01-06" "1945-01-05" "1945-01-04"

get_date_origin(wb_workbook())
#> [1] "1900-01-01"
get_date_origin(wb_workbook(), origin = TRUE)
#> [1] 25569