ycphs / openxlsx

openxlsx - a fast way to read and write complex xslx files
https://ycphs.github.io/openxlsx/
Other
220 stars 73 forks source link

Table with "auto" colwidths is hidden when calling openXL or saveWorkbook twice #440

Open jey1401 opened 11 months ago

jey1401 commented 11 months ago

Describe the bug After setting column widths to "auto", table columns are hidden in Excel on second call to openXL (or saveWorkbook). Warnings appear on second call.

To Reproduce

library(openxlsx)

wb = createWorkbook()
addWorksheet(wb, "test")
writeDataTable(wb, sheet = "test", iris)

setColWidths(wb, sheet = "test", cols = 1:5, widths = "auto")

openXL(wb) # ok
openXL(wb) # bug: table is hidden in Excel
#> Warning in .self$setColWidths(i): NAs introduced by coercion
#> Warning in .self$setColWidths(i): NAs introduced by coercion

#> Warning in .self$setColWidths(i): NAs introduced by coercion

#> Warning in .self$setColWidths(i): NAs introduced by coercion

#> Warning in .self$setColWidths(i): NAs introduced by coercion

Created on 2023-08-09 by the reprex package (v2.0.1)

Expected behavior Table columns should be shown. File should not change on successive calls to openXL or saveWorkbook.