How to set XLSX cell width with EPPlus?

前端 未结 5 1875
孤城傲影
孤城傲影 2021-01-31 00:47

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

5条回答
  •  清酒与你
    2021-01-31 01:41

    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.

提交回复
热议问题