dot-write_sheet: Safely write a data frame to an Excel worksheet

.write_sheetR Documentation

Safely write a data frame to an Excel worksheet

Description

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.

Usage

.write_sheet(wb, sheet_name, df)

Arguments

wb

An openxlsx workbook object.

sheet_name

Character scalar; name of the worksheet to create or replace.

df

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.

Details

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.

Value

Invisibly returns NULL. The workbook wb is modified in place.


bivarhr documentation built on July 7, 2026, 1:06 a.m.