Former-commit-id: 483720197ca4fbaace04554c817f8148237fba2a
Former-commit-id: 6da9c8059557c8a5898178a37affac8c677c6cea
1.0
wanggang 5 years ago
parent d3155746eb
commit 777989d7e9

@ -579,24 +579,25 @@ namespace TeacherExt.Controllers
foreach (var head in item.Headers) foreach (var head in item.Headers)
{ {
var cell = (sheet.GetRow(i)??sheet.CreateRow(i)).CreateCell(colIndex); var cell = (sheet.GetRow(i)??sheet.CreateRow(i)).CreateCell(colIndex);
cell.SetCellValue(head.Key); cell.SetStyle(style).SetCellValue(head.Key);
var length = cell.ToString().Split('\n').Select(o => Encoding.UTF8.GetBytes(o).Count()).Max()*256; //var length = cell.ToString().Split('\n').Select(o => Encoding.UTF8.GetBytes(o).Count()).Max()*256;
if (length>sheet.GetColumnWidthInPixels(colIndex)) //if (length>sheet.GetColumnWidthInPixels(colIndex))
{ //{
sheet.SetColumnWidth(colIndex, length); // sheet.SetColumnWidth(colIndex, length);
} //}
if (head.Value>1) if (head.Value>1)
{ {
for (int j = i; j < head.Value; j++) for (int j = i+1; j < head.Value; j++)
{ {
var row = sheet.GetRow(j) ?? sheet.CreateRow(j); var row = sheet.GetRow(j) ?? sheet.CreateRow(j);
(row.GetCell(colIndex)??row.CreateCell(colIndex)).SetStyle(style); (row.GetCell(colIndex)??row.CreateCell(colIndex)).SetStyle(style);
} }
sheet.AddMergedRegion(new CellRangeAddress(i,i+head.Value-1,colIndex,colIndex)); sheet.AddMergedRegion(new CellRangeAddress(i,i+head.Value-1,colIndex,colIndex));
sheet.GetRow(i).GetCell(colIndex).SetStyle(style); sheet.GetRow(i).GetCell(colIndex).SetStyle(style);
i = i + head.Value;
} }
i = i + head.Value;
} }
//sheet.AutoSizeColumn(colIndex);
colIndex += 1; colIndex += 1;
} }
} }

Loading…
Cancel
Save