setColWidths: Set worksheet column widths

Description Usage Arguments Details Author(s) See Also Examples

Description

Set worksheet column widths to specific width or "auto".

Usage

1
setColWidths(wb, sheet, cols, widths, ignoreMergedCells = FALSE)

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 or "auto" for automatic sizing. The widths argument is recycled to the length of cols.

ignoreMergedCells

Ignore any cells that have been merged with other cells in the calculation of "auto" column widths.

Details

The global min and max column width for "auto" columns is set by (default values show):

  • options("openxlsx.minWidth" = 3)

  • options("openxlsx.maxWidth" = 250) ## This is the maximum width allowed in Excel

NOTE: The calculation of column widths can be slow for large worksheets.

Author(s)

Alexander Walker

See Also

removeColWidths

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## 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))

## auto columns
addWorksheet(wb, "Sheet 2")
writeData(wb, sheet = 2, x = iris)
setColWidths(wb, sheet = 2, cols = 1:5, widths = "auto")
  
## Save workbook
saveWorkbook(wb, "setColWidthsExample.xlsx", overwrite = TRUE)


Search within the openxlsx package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.