Autofit rows in EPPlus

后端 未结 2 462
独厮守ぢ
独厮守ぢ 2021-01-03 08:05

I cannot find a way to autofit row height using the EPPlus Excel library. When I used Excel Interop, I could do sheet.Rows.AutoFit(). I\'m looking around the in

2条回答
  •  太阳男子
    2021-01-03 08:13

    Another twist to this that has taken me hours to figure out: How to enable word wrap in a given column or row. This is how I did it:

    (Horizontal and vertical alignments have been set to "Center")

          // Increase the height of the header row by .5
          // (The height is already at 2 times the default value)
          wsDT.Row(1).Height *= 1.5;
    
          // Column index to Notes, Anniversary Month and Day
          //   add "1" since column index is relative to 0
          int colIdx = dt.Columns.IndexOf("Notes") + 1;
    
          // Set the column width 
          // This is a long text field - so width and word wrap are set
          wsDT.Column(colIdx).Width = 50;
          wsDT.Column(colIdx).Style.WrapText = true;
    
          // Set width of anniversary month column
          // Purpose here is to wrap header text 
          colIdx = dt.Columns.IndexOf("Lease Anniversary Month") + 1;
          wsDT.Column(colIdx).Width = 15;
          wsDT.Column(colIdx).Style.WrapText = true;
    

    Header row showing wrapped text and set width Contents of "Notes" row has wrapped text when appropriate

提交回复
热议问题