I'm trying to center a header(s) for an excel file like so:
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;
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With