Commit 3a055eff by wyc

科室详情下载

parent 91f4531a
......@@ -222,9 +222,6 @@ public IActionResult DownloadUniteDeptdetail([FromBody] UniteDeptDetailRequest r
return BadRequest("核算组别错误");
var userid = _claim.GetUserId();
var uniteDeptDetail = _computeService.UniteDeptDetail(request.AllotId, unitType, request.AccountingUnit, userid);
//var ser = JsonConvert.SerializeObject(response);
//var rows = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(ser);
//Dictionary<string, object> rows = _computeService.ConvertToDictionary(response);
var filepath = _computeService.ExcelDownload(uniteDeptDetail, "科室绩效详情", request.AllotId);
......
......@@ -14,6 +14,7 @@
using Performance.Infrastructure;
using Performance.Repository;
using static Performance.Services.ExtractExcelService.WriteDataHelper;
using System.Drawing;
namespace Performance.Services
{
......@@ -627,10 +628,13 @@ public string ExcelDownload(UniteDeptDetailResponse uniteDeptDetail, string name
worksheet.Cells[1, 1, 1, maxColIndex].Style.Border.BorderAround(ExcelBorderStyle.Thin);
worksheet.Cells[1, 1, 1, maxColIndex].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
worksheet.Cells[1, 1, 1, maxColIndex].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
var rowIndex = 2;
worksheet.Cells[1, 1].Style.Fill.PatternType = ExcelFillStyle.Solid;
worksheet.Cells[1, 1].Style.Fill.BackgroundColor.SetColor(Color.GhostWhite);
var rowIndex = 1;
WriteSheetCells(worksheet, maxColIndex, rowIndex, uniteDeptDetail.DetailItems);
worksheet.Cells.AutoFitColumns();
int lastColumnIndex = worksheet.Dimension.End.Column;
worksheet.Column(lastColumnIndex).Width = 20;
package.Save();
}
return filepath;
......@@ -638,18 +642,20 @@ public string ExcelDownload(UniteDeptDetailResponse uniteDeptDetail, string name
int WriteSheetCells(ExcelWorksheet worksheet, int maxColIndex, int rowIndex, List<DeptDetailItem> detailItems)
{
foreach (var item in detailItems)
foreach (var item in detailItems.Where(w => w.Display))
{
worksheet.SetValue(rowIndex, 1, $"{item.Title}:{item.TotalFormat}");
++rowIndex;
worksheet.SetValue(rowIndex, 1, $"{item.Title} : {item.TotalFormat}");
worksheet.Cells[rowIndex, 1, rowIndex, maxColIndex].Merge = true;
worksheet.Cells[rowIndex, 1, rowIndex, maxColIndex].Style.Font.Bold = true;
worksheet.Cells[rowIndex, 1, rowIndex, maxColIndex].Style.Font.Size = 18;
worksheet.Cells[rowIndex, 1, rowIndex, maxColIndex].Style.Border.BorderAround(ExcelBorderStyle.Thin);
worksheet.Cells[rowIndex, 1, rowIndex, maxColIndex].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
worksheet.Cells[rowIndex, 1, rowIndex, maxColIndex].Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
worksheet.Cells[rowIndex, 1, rowIndex, maxColIndex].Style.Fill.PatternType = ExcelFillStyle.Solid;
worksheet.Cells[rowIndex, 1, rowIndex, maxColIndex].Style.Fill.BackgroundColor.SetColor(Color.GhostWhite);
if (item.Children?.Any() == true)
{
rowIndex = rowIndex + 1;
rowIndex = WriteSheetCells(worksheet, maxColIndex, rowIndex, item.Children);
}
else if (item.Items?.Any() == true)
......@@ -665,6 +671,8 @@ int WriteSheetCells(ExcelWorksheet worksheet, int maxColIndex, int rowIndex, Lis
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, 1, rowIndex, maxColIndex].Style.Fill.PatternType = ExcelFillStyle.Solid;
worksheet.Cells[rowIndex, 1, rowIndex, maxColIndex].Style.Fill.BackgroundColor.SetColor(Color.GhostWhite);
if (colIndex + 1 == headers.Count())
{
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, maxColIndex].Merge = true;
......@@ -674,6 +682,8 @@ int WriteSheetCells(ExcelWorksheet worksheet, int maxColIndex, int rowIndex, Lis
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;
worksheet.Cells[rowIndex, 1, rowIndex, maxColIndex].Style.Fill.PatternType = ExcelFillStyle.Solid;
worksheet.Cells[rowIndex, 1, rowIndex, maxColIndex].Style.Fill.BackgroundColor.SetColor(Color.GhostWhite);
}
}
foreach (var row in item.Items)
......@@ -681,17 +691,31 @@ int WriteSheetCells(ExcelWorksheet worksheet, int maxColIndex, int rowIndex, Lis
rowIndex = rowIndex + 1;
for (int colIndex = 0; colIndex < headers.Count(); colIndex++)
{
worksheet.SetValue(rowIndex, colIndex + 1, row[headers.ElementAt(colIndex)]);
object cellValue = row[headers.ElementAt(colIndex)]; // 获取单元格的值
double numericValue; // 用于存储转换后的数值
if (cellValue != null && double.TryParse(cellValue.ToString(), out numericValue))
{
if (numericValue < 0)
{
worksheet.Cells[rowIndex, colIndex + 1].Style.Fill.PatternType = ExcelFillStyle.Solid;
worksheet.Cells[rowIndex, colIndex + 1].Style.Fill.BackgroundColor.SetColor(Color.Red);
}
worksheet.SetValue(rowIndex, colIndex + 1, numericValue);
}
else
{
worksheet.SetValue(rowIndex, colIndex + 1, row[headers.ElementAt(colIndex)]);
worksheet.Cells[rowIndex, 1, rowIndex, maxColIndex].Style.Fill.PatternType = ExcelFillStyle.Solid;
worksheet.Cells[rowIndex, 1, rowIndex, maxColIndex].Style.Fill.BackgroundColor.SetColor(Color.GhostWhite);
}
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;
if (colIndex + 1 == headers.Count())
{
worksheet.Cells[rowIndex, colIndex + 1, rowIndex, maxColIndex].Merge = 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;
......
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