Learn R Programming

openxlsx (version 1.0.3)

setColWidths: Set worksheet column widths

Description

Set worksheet column widths

Usage

setColWidths(wb, sheet, cols, widths)

Arguments

wb
A workbook object
sheet
A name or index of a worksheet
cols
Indices of cols to set width
widths
widths to set rows to specified in Excel column width units.

See Also

removeColWidths

Examples

Run this code
## Create a new workbook
wb <- createWorkbook()

## Add a worksheet
addWorksheet(wb, "Sheet 1")

## set col widths
setColWidths(wb, 1, cols = c(1,4,6,7,9), widths = c(16,15,12,18,33))

## overwrite col 1 to auto width ("auto" defaults to 8.43 (excel default) if column is empty)
setColWidths(wb, 1, "A", "auto")

## Save workbook
saveWorkbook(wb, "setColWidthsExample.xlsx", overwrite = TRUE)

Run the code above in your browser using DataLab