Hello I have this code where i create an xlsx file and i need to pre set the width of the xlsx sheet cells. The actual problem is that when i open the excell i need to double c
There is an easier way. Excel will quantize the passed in column widths to display 12ths below 1 and into 7ths above. This means a staircase result and many end values cannot be made (e.g. 3.5,4.5 etc).
To pre-compensate a width the following is sufficient.
IF DesiredWidth < 1 then
AdjustedWidth = 12/7 * DesiredWidth
ELSE
AdjustedWidth = DesiredWidth + 5/7
ENDIF
Write Worksheet.Column(i).Width = AdjustedWidth with EPPLUS
This is a monotonic adjustment and Excel does all of the quantizing on open/save.