47 lines
1.8 KiB
C#
47 lines
1.8 KiB
C#
using System.Drawing;
|
|
using CompanyManagment.App.Contracts.Workshop;
|
|
using OfficeOpenXml;
|
|
using OfficeOpenXml.Style;
|
|
|
|
namespace CompanyManagement.Infrastructure.Excel.WorkshopsRollCall;
|
|
|
|
public class WorkshopRollCallExcelExporter
|
|
{
|
|
public static byte[] Export(List<WorkshopRollCallExcelViewModel> workshops)
|
|
{
|
|
ExcelPackage.License.SetNonCommercialOrganization("Gozareshgir Noncommercial organization");
|
|
using (var package = new ExcelPackage())
|
|
{
|
|
var ws = package.Workbook.Worksheets.Add("Workshops");
|
|
// Header
|
|
ws.Cells[1, 1].Value = "نام کارگاه";
|
|
ws.Cells[1, 2].Value = "فعال/غیرفعال";
|
|
ws.Cells[1, 3].Value = "تعداد پرسنل";
|
|
ws.Cells[1, 4].Value = "نام کارفرما";
|
|
ws.Row(1).Style.Font.Bold = true;
|
|
ws.Row(1).Style.Fill.PatternType = ExcelFillStyle.Solid;
|
|
ws.Row(1).Style.Fill.BackgroundColor.SetColor(Color.LightGray);
|
|
|
|
int row = 2;
|
|
foreach (var w in workshops)
|
|
{
|
|
ws.Cells[row, 1].Value = w.WorkshopName;
|
|
ws.Cells[row, 2].Value = w.IsActive ? "فعال" : "غیرفعال";
|
|
ws.Cells[row, 3].Value = w.PersonnelCount;
|
|
ws.Cells[row, 4].Value = w.EmployerName;
|
|
if (!w.IsActive)
|
|
{
|
|
using (var range = ws.Cells[row, 1, row, 4])
|
|
{
|
|
range.Style.Fill.PatternType = ExcelFillStyle.Solid;
|
|
range.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
|
|
}
|
|
}
|
|
row++;
|
|
}
|
|
ws.Cells[ws.Dimension.Address].AutoFitColumns();
|
|
return package.GetAsByteArray();
|
|
}
|
|
}
|
|
|
|
} |