10

I'm trying to center a header(s) for an excel file like so: Excel Table

But I am missing a few details, since the code below one writes on one line and does not expand the cell's height. Here is my code so far:

ws.Cells[$"A{row}:F{row}"].Merge = true;
ws.Cells[$"A{row}"].Style.WrapText = true;
ws.SelectedRange[$"A{row}"].Value = purchaseHistory[0].LineText;
Beshoy Hanna
  • 611
  • 2
  • 9
  • 29

1 Answers1

10

To center the merged cell both vertical and horizontally just do this:

//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 the height of the rows you will want to look at the CustomHeight setting. This should explain it: Autofit rows in EPPlus

Community
  • 1
  • 1
Ernie S
  • 13,902
  • 4
  • 52
  • 79