Skip to content

Commit

Permalink
Add support for minWidth and adding defaults to avoid having comparis…
Browse files Browse the repository at this point in the history
…ons to `logical(0)`
  • Loading branch information
olivroy committed Nov 14, 2023
1 parent fbfa9b6 commit 2dc36f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

* Improve copying cells in transpose mode and with hyperlinks. [850](https://github.com/JanMarvin/openxlsx2/pull/850)

* Options `openxlsx2.maxWidth` and `openxlsx2.minWidth` are now respected as documented when setting column widths with `wb_set_col_widths()`. [847](https://github.com/JanMarvin/openxlsx2/issues/847)

***************************************************************************

Expand Down
10 changes: 8 additions & 2 deletions R/converters.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,14 @@ calc_col_width <- function(base_font, col_width) {
# to the expected widths
widths <- trunc((as.numeric(col_width) * mdw + 5) / mdw * 256) / 256
widths <- round(widths, 3)
if (any(sel <- widths > getOption("openxlsx2.maxWidth"))) {
widths[sel] <- getOption("openxlsx2.maxWidth")

if (any(sel <- widths > getOption("openxlsx2.maxWidth", 250))) {
widths[sel] <- getOption("openxlsx2.maxWidth", 250)
}

if (any(sel <- widths <= getOption("openxlsx2.minWidth", 0))) {
widths[sel] <- getOption("openxlsx2.minWidth", 1)
}

widths
}

0 comments on commit 2dc36f0

Please sign in to comment.