|
|
|
@ -171,25 +171,37 @@ namespace TeacherExt.Controllers
|
|
|
|
|
var colWidthList = new System.Collections.Generic.Dictionary<int, int>();
|
|
|
|
|
for (int i = 0; i < rowIndex; i++)
|
|
|
|
|
{
|
|
|
|
|
var row = sheet.GetRow(i + 1);
|
|
|
|
|
var row = sheet.GetRow(i);
|
|
|
|
|
for (int j = 0; j < colIndex; j++)
|
|
|
|
|
{
|
|
|
|
|
var key = j + 1;
|
|
|
|
|
var cell = sheet.GetRow(i).GetCell(key);
|
|
|
|
|
if(!colWidthList.ContainsKey(key))
|
|
|
|
|
var cell = sheet.GetRow(i).GetCell(j);
|
|
|
|
|
if (!colWidthList.ContainsKey(j))
|
|
|
|
|
{
|
|
|
|
|
colWidthList.Add(key, 0);
|
|
|
|
|
colWidthList.Add(j, 0);
|
|
|
|
|
}
|
|
|
|
|
var length = Encoding.UTF8.GetBytes(cell.ToString()).Count() + 1;
|
|
|
|
|
if(length> colWidthList[key])
|
|
|
|
|
var value = cell.ToString();
|
|
|
|
|
var array = value.Split('\n');
|
|
|
|
|
var length = array.Select(o => Encoding.UTF8.GetBytes(o).Count()).Max() + 2;
|
|
|
|
|
if (length > colWidthList[j])
|
|
|
|
|
{
|
|
|
|
|
colWidthList[key] = length;
|
|
|
|
|
if (!cell.IsMergedCell)
|
|
|
|
|
{
|
|
|
|
|
colWidthList[j] = length;
|
|
|
|
|
Console.WriteLine($">>>>>{j}:{length}:{value}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach (var item in colWidthList.Keys)
|
|
|
|
|
{
|
|
|
|
|
sheet.SetColumnWidth(item,colWidthList[item]*256);
|
|
|
|
|
var width = colWidthList[item] * 256;
|
|
|
|
|
if (width == 0)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
sheet.SetColumnWidth(item, width);
|
|
|
|
|
Console.WriteLine($"{sheet.GetRow(2).GetCell(item)}:{item}:{colWidthList[item]}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|