R - Autofit Excel column width

后端 未结 4 1920
再見小時候
再見小時候 2021-02-02 01:30

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

4条回答
  •  时光取名叫无心
    2021-02-02 02:00

    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.

提交回复
热议问题