CourseWork_EventVisitor/EventVisitor/EventVisitorLogic/OfficePackage/AbstractSaveToExcel.cs

92 lines
3.1 KiB
C#
Raw Normal View History

using EventVisitorLogic.OfficePackage.HelperEnums;
using EventVisitorLogic.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorLogic.OfficePackage
{
public abstract class AbstractSaveToExcel
{
public void CreateReport(ExcelInfo info)
{
CreateExcel(info);
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = 1,
Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title
});
2024-12-02 02:20:47 +04:00
MergeCells(new ExcelMergeParameters
{
CellFromName = "A1",
CellToName = "F1"
});
uint rowIndex = 2;
foreach (var pc in info.Visitors)
{
2024-12-02 02:20:47 +04:00
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = pc.Name,
StyleInfo = ExcelStyleInfoType.Text
});
2024-12-02 02:20:47 +04:00
MergeCells(new ExcelMergeParameters
{
CellFromName = $"A{rowIndex}",
CellToName = $"B{rowIndex}"
});
InsertCellInWorksheet(new ExcelCellParameters
{
2024-12-02 02:20:47 +04:00
ColumnName = "C",
RowIndex = rowIndex,
Text = pc.Email,
StyleInfo = ExcelStyleInfoType.Text
});
2024-12-02 02:20:47 +04:00
MergeCells(new ExcelMergeParameters
{
CellFromName = $"C{rowIndex}",
CellToName = $"D{rowIndex}"
});
InsertCellInWorksheet(new ExcelCellParameters
{
2024-12-02 02:20:47 +04:00
ColumnName = "E",
RowIndex = rowIndex,
Text = pc.Phone,
StyleInfo = ExcelStyleInfoType.Text
});
2024-12-02 02:20:47 +04:00
MergeCells(new ExcelMergeParameters
{
CellFromName = $"E{rowIndex}",
CellToName = $"F{rowIndex}"
});
InsertCellInWorksheet(new ExcelCellParameters
{
2024-12-02 02:20:47 +04:00
ColumnName = "G",
RowIndex = rowIndex,
Text = pc.Status,
StyleInfo = ExcelStyleInfoType.Text
});
2024-12-02 02:20:47 +04:00
MergeCells(new ExcelMergeParameters
{
CellFromName = $"G{rowIndex}",
CellToName = $"H{rowIndex}"
});
rowIndex++;
}
SaveExcel(info);
}
protected abstract void CreateExcel(ExcelInfo info);
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
protected abstract void MergeCells(ExcelMergeParameters excelParams);
protected abstract void SaveExcel(ExcelInfo info);
}
}