Learn R Programming

writexl (version 2.0.0)

xl_rich_string: A cell whose text has several formats

Description

`xl_rich_string()` builds the value of a single cell out of differently formatted runs, so that one cell can read "This is **bold** text". Pass it as the `value` of [xl_cell_general()].

Excel requires at least two runs: a string with one format is an ordinary character value, so pass it as one.

`as.character()` returns the cell's text with the per-run fonts dropped.

Usage

xl_rich_string(...)

is_xl_rich_string(x)

# S3 method for xl_rich_string as.character(x, ...)

Value

An `xl_rich_string` object: a list of runs.

Arguments

...

Runs, in order. A bare string is taken as an unformatted run; an [xl_rich_run()] carries its own font. Lists of either are flattened, so runs can be assembled programmatically.

x

An object to test.

See Also

[xl_rich_run], [xl_cell_general], [xl_font]

Other cell content: is_xl_comment(), xl_cell_general(), xl_comment(), xl_formula(), xl_rich_run()

Examples

Run this code
xl_rich_string("This is ", xl_rich_run("bold", xl_font(bold = TRUE)), " text")

# in a cell, with a cell-wide format alongside the per-run fonts
xl_cell_general(
  value  = xl_rich_string("2 H", xl_rich_run("2", xl_font(script = "sub")), "O"),
  format = xl_align(horizontal = "center")
)

Run the code above in your browser using DataLab