Helper to write a data frame into an openxlsx workbook as a table, replacing any existing sheet with the same name, applying basic formatting, and handling empty data frames gracefully.
.write_sheet(wb, sheet_name, df)Invisibly returns NULL. The workbook wb is
modified in place.
An openxlsx workbook object.
Character scalar; name of the worksheet to create or replace.
A data frame to write. If df is NULL or has
zero rows or columns, a placeholder data frame with a single column
info = "Sin datos" is written instead.
The function:
Removes the sheet sheet_name if it already exists.
Adds a new worksheet with that name.
Writes df as a data table and freezes the first row.
Sets column widths to "auto".
Applies a bold style to the header row.