set_xlsx_colwidths: Set column widths in Xlsx files

set_xlsx_colwidthsR Documentation

Set column widths in Xlsx files

Description

Set column widths in Xlsx files

Usage

set_xlsx_colwidths(
  xlsxFile,
  sheet = 1,
  cols = seq_along(widths),
  widths = 11,
  ...
)

Arguments

xlsxFile

character filename to a file with ".xlsx" extension, or Workbook object defined in the openxlsx package. When xlsxFile is a Workbook the output is not saved to a file.

sheet

value passed to openxlsx::setColWidths() indicating the worksheet to affect. It can either be an integer value, or the character name of a sheet.

cols

⁠integer vector⁠ indicating the column numbers to affect.

widths

⁠numeric vector⁠ indicating the width of each column defined by cols.

...

additional arguments are passed to openxlsx::setColWidths().

Details

This function is a light wrapper to perform these steps from the very useful openxlsx R package:

  • openxlsx::loadWorkbook()

  • openxlsx::setColWidths()

  • openxlsx::saveWorkbook()

Value

Workbook object as defined by the openxlsx package is returned invisibly with invisible(). This Workbook can be used in argument wb to provide a speed boost when saving multiple sheets to the same file.

See Also

Other jam export functions: applyXlsxCategoricalFormat(), applyXlsxConditionalFormat(), readOpenxlsx(), set_xlsx_rowheights(), writeOpenxlsx()

Examples

## Not run: 
   df <- data.frame(a=LETTERS[1:5], b=1:5);
   jamba::writeOpenxlsx(x=df,
      file="jamba_test.xlsx",
      sheetName="test_jamba");

   ## By default, cols starts at column 1 and continues to length(widths)
   jamba::set_xlsx_colwidths(file="jamba_test.xlsx",
      sheetName="test_jamba",
      widths=rep(20, ncol(df))
   )

## End(Not run)


jmw86069/jamba documentation built on Oct. 9, 2024, 10:52 a.m.