`xl_col_spec()` and `xl_row_spec()` describe formatting and geometry for a set of columns or rows within a sheet built by [xl_sheet()]. They are *subclasses* of [xl_format]: they carry the usual formatting groups (so they combine with `+` and the group constructors) plus a target (which columns/rows) and geometry (width/height, hidden, outline level).
Usage
xl_col_spec(
cols,
width = NA,
hidden = NA,
level = NA,
format = NULL,
width_pixels = NA
)
xl_row_spec(
rows,
height = NA,
hidden = NA,
level = NA,
format = NULL,
height_pixels = NA
)Arguments
- cols
Columns to target: a character vector of column names or a numeric vector of 1-based positions.
- width
Column width (in Excel character units).
Logical; hide the column/row.
- level
Integer outline (grouping) level, 0–7.
- format
An optional [xl_format] applied to the column/row as its default cell format. Combine groups with `+` (e.g. `xl_font(bold = TRUE) + xl_fill(background = "yellow")`).
- width_pixels, height_pixels
The same geometry given in pixels instead. Give one or the other, not both. Excel stores character units and points, so the pixel value is converted on the way in — read back, a width set as 100 pixels is 13.57 character units.
- rows
Rows to target: a numeric vector of 1-based data-row indices (row 1 is the first data row, ignoring the header).
- height
Row height (in points).
See also
[xl_sheet], [xl_format]
Other worksheet layout:
xl_outline(),
xl_page_setup(),
xl_sheet(),
xl_sheet_view()
Examples
xl_col_spec("revenue", width = 14, format = xl_num_format("#,##0.00"))
#> <xl_col_spec>
#> target: kind=col, index=revenue
#> geometry: width=14
#> num_format: format=#,##0.00
xl_col_spec(c(1, 2), width = 10) + xl_font(bold = TRUE)
#> <xl_col_spec>
#> target: kind=col, index=1,2
#> geometry: width=10
#> font: bold=TRUE
xl_col_spec("logo", width_pixels = 100)
#> <xl_col_spec>
#> target: kind=col, index=logo
#> geometry: width=13.57143
xl_row_spec(1, height = 24, format = xl_font(bold = TRUE))
#> <xl_row_spec>
#> target: kind=row, index=1
#> geometry: height=24
#> font: bold=TRUE
xl_row_spec(1, height_pixels = 40)
#> <xl_row_spec>
#> target: kind=row, index=1
#> geometry: height=30
