awalker89 / openxlsx

R package for .xlsx file reading and writing.
Other
364 stars 79 forks source link

set default column width #425

Open tobwen opened 5 years ago

tobwen commented 5 years ago

Expected Behavior

I want to set MS Excel's default column width to 10.71 (80 px) for all columns in a worksheet.

Actual Behavior

minWidth is ignored or can't be used as a default min-width

Steps to Reproduce the Problem

options("openxlsx.minWidth" = 10.71)
wb <- createWorkbook()
addWorksheet(wb, "test")
  freezePane(wb, sheet = 1, firstRow = TRUE)
setColWidths(wb, sheet = 1, cols = 1:ncol(data), widths = "auto")
saveWorkbook(wb, tempfile(), overwrite = TRUE)

Hack, which creates much bigger files: setColWidths(wb, sheet = 1, cols = ncol(data):16384, widths = 10.71)

sessionInfo()

tobwen commented 4 years ago

fix

https://github.com/awalker89/openxlsx/blob/ead0038c59a227faa5c03f13aa7c6211f63dc9e0/R/worksheet_class.R#L55

change

<sheetFormatPr defaultRowHeight="15.0"/>

to

<sheetFormatPr defaultRowHeight="15.0" baseColWidth="10"/>