vb.net 在单元格中居中、合并和换行文本 - EPPlus
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36652737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Centering, Merging, and Wrapping Text In Cells - EPPlus
提问by Beshoy Hanna
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;
回答by Ernie S
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 CustomHeightsetting. This should explain it: Autofit rows in EPPlus
如果您需要对行的高度做一些事情,您将需要查看CustomHeight设置。这应该解释一下: EPPlus 中的自动调整行

