NPOI下,怎样自适应行高,因为没有现成的方法,使用如下逻辑兼容自适应方法,适用于03,07版本导出,使用于字符,数字,字母等
for (int i = 0; i < Rows.Count; i++)
{
if (sheet.GetRow(i) == null)
{
continue;
}
IRow ICurRow = sheet.GetRow(i);
int OldHg = ICurRow.Height;
for (int j = 0; j < Cols.Count; j++)
{
if (ICurRow.GetCell(j) == null)
{
continue;
}
ICell CurCell = ICurRow.GetCell(j);
if (CurCell.CellType == NPOI.SS.UserModel.CellType.String && CurCell.StringCellValue != string.Empty)
{
double CurHeight = ICurRow.Sheet.GetColumnWidth(CurCell.ColumnIndex) / 277;
double length = Encoding.Default.GetBytes(CurCell.ToString()).Length;
short height = Convert.ToInt16(Math.Ceiling(length / CurHeight));
if (height * 256 > OldHg)
{
OldHg = height * 256 ;
}
}
}
if (ICurRow.Height < OldHg)
{
ICurRow.Height = Convert.ToInt16(OldHg);
}
}