Learn R Programming

bivarhr (version 0.1.5)

.write_sheet: 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)

Value

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

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.