Commit 91f4531a by ruyun.zhang

下载样式

parent 8a4b5ea4
...@@ -628,7 +628,6 @@ public string ExcelDownload(UniteDeptDetailResponse uniteDeptDetail, string name ...@@ -628,7 +628,6 @@ public string ExcelDownload(UniteDeptDetailResponse uniteDeptDetail, string name
worksheet.Cells[1, 1, 1, maxColIndex].Style.VerticalAlignment = ExcelVerticalAlignment.Center; worksheet.Cells[1, 1, 1, maxColIndex].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
worksheet.Cells[1, 1, 1, maxColIndex].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; worksheet.Cells[1, 1, 1, maxColIndex].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
var rowIndex = 2; var rowIndex = 2;
WriteSheetCells(worksheet, maxColIndex, rowIndex, uniteDeptDetail.DetailItems); WriteSheetCells(worksheet, maxColIndex, rowIndex, uniteDeptDetail.DetailItems);
...@@ -661,15 +660,21 @@ int WriteSheetCells(ExcelWorksheet worksheet, int maxColIndex, int rowIndex, Lis ...@@ -661,15 +660,21 @@ int WriteSheetCells(ExcelWorksheet worksheet, int maxColIndex, int rowIndex, Lis
{ {
worksheet.SetValue(rowIndex, colIndex + 1, headers.ElementAt(colIndex)); worksheet.SetValue(rowIndex, colIndex + 1, headers.ElementAt(colIndex));
var toCol = colIndex + 1 == headers.Count() ? colIndex : maxColIndex; worksheet.Cells[rowIndex, colIndex + 1].Style.Font.Bold = true;
worksheet.Cells[rowIndex, colIndex + 1].Style.Font.Size = 16;
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, toCol + 1].Merge = colIndex + 1 == headers.Count(); worksheet.Cells[rowIndex, colIndex + 1].Style.Border.BorderAround(ExcelBorderStyle.Thin);
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, toCol + 1].Style.Font.Bold = true; worksheet.Cells[rowIndex, colIndex + 1].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, toCol + 1].Style.Font.Size = 16; worksheet.Cells[rowIndex, colIndex + 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, toCol + 1].Style.Border.BorderAround(ExcelBorderStyle.Thin); if (colIndex + 1 == headers.Count())
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, toCol + 1].Style.VerticalAlignment = ExcelVerticalAlignment.Center; {
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, toCol + 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; worksheet.Cells[rowIndex, colIndex + 1, rowIndex, maxColIndex].Merge = true;
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, maxColIndex].Style.Font.Bold = true;
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, maxColIndex].Style.Font.Size = 16;
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, maxColIndex].Style.Border.BorderAround(ExcelBorderStyle.Thin);
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, maxColIndex].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, maxColIndex].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
}
} }
foreach (var row in item.Items) foreach (var row in item.Items)
{ {
...@@ -678,13 +683,20 @@ int WriteSheetCells(ExcelWorksheet worksheet, int maxColIndex, int rowIndex, Lis ...@@ -678,13 +683,20 @@ int WriteSheetCells(ExcelWorksheet worksheet, int maxColIndex, int rowIndex, Lis
{ {
worksheet.SetValue(rowIndex, colIndex + 1, row[headers.ElementAt(colIndex)]); worksheet.SetValue(rowIndex, colIndex + 1, row[headers.ElementAt(colIndex)]);
var toCol = colIndex + 1 == headers.Count() ? colIndex : maxColIndex; worksheet.Cells[rowIndex, colIndex + 1].Style.Font.Size = 16;
worksheet.Cells[rowIndex, colIndex + 1].Style.Border.BorderAround(ExcelBorderStyle.Thin);
worksheet.Cells[rowIndex, colIndex + 1].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
worksheet.Cells[rowIndex, colIndex + 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, toCol + 1].Merge = colIndex + 1 == headers.Count(); if (colIndex + 1 == headers.Count())
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, toCol + 1].Style.Font.Size = 16; {
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, toCol + 1].Style.Border.BorderAround(ExcelBorderStyle.Thin); worksheet.Cells[rowIndex, colIndex + 1, rowIndex, maxColIndex].Merge = true;
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, toCol + 1].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, toCol + 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; worksheet.Cells[rowIndex, colIndex + 1, rowIndex, maxColIndex].Style.Font.Size = 16;
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, maxColIndex].Style.Border.BorderAround(ExcelBorderStyle.Thin);
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, maxColIndex].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, maxColIndex].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment