How do I autofit the column width using openxlsx
?
One of my columns has a date variable (eg. 21-08-2017
) and if copied using ctrl+c
Ok, I got it after another extensive search in the documentation. It seems very few people actually use this from the dearth of solutions online...
setColWidths(WB, Sheet, cols = 1:ncol(DF), widths = "auto")
However, this still does not give the desired result, the date column is still a bit short and shows ########
; while the column headers are not fitting as well (as they are formatted bold).
EDIT:
Finally, chose to add c(7.5, 10, "auto", ...)
replacing just "auto"
, it is not totally dynamic, but solves the issue for now. Hope to see better answers.