Skip to contents

Helper to add shared hyperlinks into a worksheet or remove shared hyperlinks from a worksheet

Usage

wb_add_hyperlink(
  wb,
  sheet = current_sheet(),
  dims = "A1",
  target = NULL,
  tooltip = NULL,
  is_external = TRUE,
  col_names = FALSE
)

wb_remove_hyperlink(wb, sheet = current_sheet(), dims = NULL)

Arguments

wb

A Workbook object containing a worksheet.

sheet

The worksheet to write to. (either as index or name)

dims

Spreadsheet dimensions that will determine where the hyperlink reference spans: "A1", "A1:B2", "A:B"

target

An optional target, if no target is specified, it is assumed that the cell already contains a reference (the cell could be a url or a filename)

tooltip

An optional description for a variable that will be visible when hovering over the link text in the spreadsheet

is_external

A logical indicating if the hyperlink is external (a url, a mail address, a file) or internal (a reference to worksheet cells)

col_names

Whether or not the object contains column names. If yes the first column of the dimension will be ignored

Details

There are multiple ways to add hyperlinks into a worksheet. One way is to construct a formula with create_hyperlink() another is to assign a class hyperlink to a column of a data frame. Contrary to the previous method, shared hyperlinks are not cell formulas in the worksheet, but references in the worksheet relationship and hyperlinks in the worksheet xml structure. These shared hyperlinks can be reused and they are not visible to spreadsheet users as HYPERLINK() formulas.

Examples

wb <- wb_workbook()$add_worksheet()$
  add_data(x = "openxlsx2 on CRAN")$
  add_hyperlink(target = "https://cran.r-project.org/package=openxlsx2",
                tooltip = "The canonical form to link to our CRAN page.")

wb$remove_hyperlink()