Former-commit-id: e2a4d6e2f67c177eb89b353476a37feb84992d51
Former-commit-id: 4f374847b0fb9ea50923b376da12c73925d2c174
1.0
wanggang 5 years ago
parent 3068b81037
commit 45098aa0ae

@ -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]}");
}
}

@ -15,7 +15,6 @@
<ItemGroup>
<None Include="wwwroot\lib\kindeditor\kindeditor-all-min.js" />
<None Include="wwwroot\lib\kindeditor\lang\zh-CN.js" />
<None Include="wwwroot\teacher.xlsx" />
</ItemGroup>
<ItemGroup>
@ -26,9 +25,4 @@
<ItemGroup>
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" />
</ItemGroup>
<ItemGroup>
<Content Update="wwwroot\teacher.xlsx">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

Loading…
Cancel
Save