【发布时间】:2020-09-17 01:11:42
【问题描述】:
设置列的 WrapText=true 后,我想查看行的新高度(即文本是否换行,多少行)。似乎没有更新行的 Height 属性。
ExcelPackage pkg = new ExcelPackage();
ExcelWorksheet sheet = pkg.Workbook.Worksheets.Add("Test");
// height is 15.0
double heightBefore = sheet.Row(1).Height;
sheet.Cells[1, 1].Value = "Now is the time for all good men to come to the aid of their country";
ExcelColumn col = sheet.Column(1);
// this will resize the width to 60
col.AutoFit();
if (col.Width > 50)
{
col.Width = 50;
// this is just a style property, and doesn't actually execute any recalculations
col.Style.WrapText = true;
}
// so this is still 15.0. How do I get it to compute what the size will be?
double heightAfter = sheet.Row(1).Height;
// open the xls, and the height is 30.0
pkg.SaveAs(new System.IO.FileInfo("text.xlsx"));
事实上,对 Height 属性(或基础字段 _height)的搜索表明它仅由属性设置器设置,并且似乎从未基于其他任何内容(如行中的内容)进行设置。
关于如何获得刷新的连续高度的任何想法?
谢谢
【问题讨论】:
标签: epplus