C# 在单元格中居中、合并和换行文字-EPPlus

C# 在单元格中居中、合并和换行文字-EPPlus,c#,.net,vb.net,epplus,C#,.net,Vb.net,Epplus,我正在尝试将excel文件的标题居中,如下所示: 但我遗漏了一些细节,因为下面的代码写在一行上,不会扩展单元格的高度。以下是我目前的代码: ws.Cells[$"A{row}:F{row}"].Merge = true; ws.Cells[$"A{row}"].Style.WrapText = true; ws.SelectedRange[$"A{row}"].Value = purchaseHistory[0].LineText; 要使合并单元格垂直和水平居中,只需执行以下操作: //On

我正在尝试将excel文件的标题居中,如下所示:

但我遗漏了一些细节,因为下面的代码写在一行上,不会扩展单元格的高度。以下是我目前的代码:

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

要使合并单元格垂直和水平居中,只需执行以下操作:

//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;
如果需要对行的高度进行调整,则需要查看
CustomHeight
设置。这应该可以解释: