Learn R Programming

openxlsx2 (version 0.3.1)

xl_open: Open a Microsoft Excel file (xls/xlsx) or an openxlsx2 wbWorkbook

Description

This function tries to open a Microsoft Excel (xls/xlsx) file or an openxlsx2 wbWorkbook with the proper application, in a portable manner.

In Windows it uses base::shell.exec() (Windows only function) to determine the appropriate program.

In Mac (c) it uses system default handlers, given the file type.

In Linux it searches (via which) for available xls/xlsx reader applications (unless options('openxlsx2.excelApp') is set to the app bin path), and if it finds anything, sets options('openxlsx2.excelApp') to the program chosen by the user via a menu (if many are present, otherwise it will set the only available). Currently searched for apps are Libreoffice/Openoffice (soffice bin), Gnumeric (gnumeric) and Calligra Sheets (calligrasheets).

Usage

xl_open(x, file, interactive = NA)

# S3 method for wbWorkbook xl_open(x, file, interactive = NA)

# S3 method for default xl_open(x, file, interactive = NA)

Arguments

x

A path to the Excel (xls/xlsx) file or Workbook object.

file

Deprecated

interactive

If FALSE will throw a warning and not open the path. This can be manually set to TRUE, otherwise when NA (default) uses the value returned from base::interactive()

Examples

Run this code
# \donttest{
if (interactive()) {
  xlsxFile <- system.file("extdata", "readTest.xlsx", package = "openxlsx2")
  xl_open(xlsxFile)

  # (not yet saved) Workbook example
  wb <- wb_workbook()
  x <- mtcars[1:6, ]
  wb$add_worksheet("Cars")
  wb$add_data("Cars", x, startCol = 2, startRow = 3, rowNames = TRUE)
  xl_open(wb)
}
# }

Run the code above in your browser using DataLab