I've noticed recently when I create excel workbooks using the openxlsx package that it produces a spreadsheet with a default column width of 10.71 rather than the usual 8.43 that we would normally get in excel. For example, if I run the following code to create a totally blank excel spreadsheet, all columns come out at 10.71 width.
wb <- openxlsx::createWorkbook()
openxlsx::addWorksheet(wb, "Sheet 1")
openxlsx::saveWorkbook(wb, "Test File.xlsx", overwrite = TRUE)
Does anyone know how to set the default column width back to the standard 8.43? I know that I can run the following to change the column widths, but this is adds additional formatting onto the spreadsheet, which will increase my file size once I've pulled in a larger dataset. It also means that the columns from my dataframe that has been exported to excel will be a different width to the columns off to the right hand side of the data (it seems trivial, but I'd like to keep things neat if possible).
openxlsx::setColWidths(wb, "Sheet 1", cols = 1:ncol(df), widths = "8.43")
There doesn't appear to be anything inside openxlsx::op.openxlsx that describes column widths, which seems a bit odd to me.
Apologies if this is a dumb question, or if I'm missing something simple, but I haven't been able to find anything about this online.
The default argument for width
actually is 8.43 as can be seen in the help function ?setColWidth
. So there's probably another reason that's interfering here.
What does openxlsx_getOp("minWidth")
give? The default is 3, but maybe you changed this to 10.71?
In case you are not creating the workbook from scratch and rather read in an existing file, this might also explain the difference (in case the read-in file has a width of 10.71).
Update: I can confirm the issue with the default settings having column width of 10.71 instead of 8.43. So my suggestion would be to open a bug on the developer's page here: https://github.com/ycphs/openxlsx/issues