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, orWorkbook
object defined in theopenxlsx
package. WhenxlsxFile
is aWorkbook
the output is not saved to a file.- sheet
integer
sheet number orcharacter
sheet name, passed toopenxlsx::setColWidths()
indicating the worksheet to affect.- cols
integer vector
indicating the column numbers to affect.- widths
numeric vector
indicating the width of each column defined bycols
.- ...
additional arguments are passed to
openxlsx::setColWidths()
.
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.
Details
This function is a light wrapper to perform these steps
from the very useful openxlsx
R package:
See also
Other jam export functions:
applyXlsxCategoricalFormat()
,
applyXlsxConditionalFormat()
,
readOpenxlsx()
,
set_xlsx_rowheights()
,
writeOpenxlsx()
Examples
# write to tempfile for examples
if (check_pkg_installed("openxlsx")) {
out_xlsx <- tempfile(pattern="writeOpenxlsx_", fileext=".xlsx")
df <- data.frame(a=LETTERS[1:5], b=1:5);
writeOpenxlsx(x=df,
file=out_xlsx,
sheetName="jamba_test");
## By default, cols starts at column 1 and continues to length(widths)
set_xlsx_colwidths(out_xlsx,
sheet="jamba_test",
widths=rep(20, ncol(df))
)
}