Skip to contents

Applies consistent formatting to a data frame that has been written into a worksheet. This includes adding a bottom border and bold font to column names, centering all cells, formatting numeric columns to two decimal places, and auto-adjusting column widths.

Usage

style_table(wb, sheet, df, numfmt = "0.00")

Arguments

wb

A openxlsx2::wb_workbook object.

sheet

Character or integer. The target worksheet name or index.

df

A data frame that has been written to sheet and needs styling.

numfmt

see openxlsx2::wb_add_numfmt

Value

The modified wb_workbook object with styles applied.

Examples

if (FALSE) { # \dontrun{
library(openxlsx2)
df <- data.frame(Name = c("A", "B"), Value = c(1.234, 2.345))
wb <- wb_workbook()
wb <- wb |>
  wb_add_worksheet("Data") |>
  wb_add_data("Data", x = df)
wb <- style_table(wb, "Data", df)
wb_save(wb, "styled.xlsx")
} # }