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>(); var colWidthList = new System.Collections.Generic.Dictionary<int, int>();
for (int i = 0; i < rowIndex; i++) 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++) for (int j = 0; j < colIndex; j++)
{ {
var key = j + 1; var cell = sheet.GetRow(i).GetCell(j);
var cell = sheet.GetRow(i).GetCell(key); if (!colWidthList.ContainsKey(j))
if(!colWidthList.ContainsKey(key))
{ {
colWidthList.Add(key, 0); colWidthList.Add(j, 0);
} }
var length = Encoding.UTF8.GetBytes(cell.ToString()).Count() + 1; var value = cell.ToString();
if(length> colWidthList[key]) 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) 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> <ItemGroup>
<None Include="wwwroot\lib\kindeditor\kindeditor-all-min.js" /> <None Include="wwwroot\lib\kindeditor\kindeditor-all-min.js" />
<None Include="wwwroot\lib\kindeditor\lang\zh-CN.js" /> <None Include="wwwroot\lib\kindeditor\lang\zh-CN.js" />
<None Include="wwwroot\teacher.xlsx" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -26,9 +25,4 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" /> <ProjectReference Include="..\Infrastructure\Infrastructure.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Update="wwwroot\teacher.xlsx">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project> </Project>

Loading…
Cancel
Save