Center, Merge, and Wrap Text Cells - EPPlus

I am trying to center the header for an excel file as follows: Excel spreadsheet

But I am missing a few details, since the code below is written on one line and does not increase the height of the cell. Here is my code:

ws.Cells[$"A{row}:F{row}"].Merge = true;
ws.Cells[$"A{row}"].Style.WrapText = true;
ws.SelectedRange[$"A{row}"].Value = purchaseHistory[0].LineText;
+4
source share
1 answer

To center a merged cell both vertically and horizontally, do the following:

//Only need to grab the first cell of the merged range
ws.Cells[$"A{row}"].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
ws.Cells[$"A{row}"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;

If you need to do something with row height, you need to look at the parameter CustomHeight. That should explain this: Auto-matching strings in EPPlus

+6
source

All Articles