Style a Data Frame Table in an openxlsx2 Workbook
style_table.RdApplies 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.
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
sheetand needs styling.- numfmt
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")
} # }