diff --git a/FurnitureFactory/FurnitureContracts/ViewModel/ReportSalesSalonViewModel.cs b/FurnitureFactory/FurnitureContracts/ViewModel/ReportSalesSalonViewModel.cs new file mode 100644 index 0000000..2e60cdc --- /dev/null +++ b/FurnitureFactory/FurnitureContracts/ViewModel/ReportSalesSalonViewModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureContracts.ViewModel +{ + public class ReportSalesSalonViewModel + { + public string SalesSalpnTitle { get; set; } = string.Empty; + public string OrderTitle { get; set; } = string.Empty; + public DateTime Date { get; set; } + public string HeadsetTitle { get; set; } = string.Empty; + } +} diff --git a/FurnitureFactory/FurnitureContracts/ViewModel/ReportSalesSalonsFurnitureViewModel.cs b/FurnitureFactory/FurnitureContracts/ViewModel/ReportSalesSalonsFurnitureViewModel.cs new file mode 100644 index 0000000..94d9a1f --- /dev/null +++ b/FurnitureFactory/FurnitureContracts/ViewModel/ReportSalesSalonsFurnitureViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureContracts.ViewModel +{ + public class ReportSalesSalonsFurnitureViewModel + { + public string Name { get; set; } = string.Empty; + public List Furniture { get; set; } = new(); + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/FurnitureFactoryBusinessLogic.csproj b/FurnitureFactory/FurnitureFactoryBusinessLogic/FurnitureFactoryBusinessLogic.csproj index 8e58883..2fcc5e8 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/FurnitureFactoryBusinessLogic.csproj +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/FurnitureFactoryBusinessLogic.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -6,14 +6,19 @@ enable + + + + + + + + + - - - - diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs index ca90df5..cb0363f 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums +namespace FurnitureFactoryBusinessLogic.OfficePackage.HelperEnums { public enum PdfParagraphAlignmentType { diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperEnums/PdfRowParameters.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperEnums/PdfRowParameters.cs new file mode 100644 index 0000000..9ee1517 --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperEnums/PdfRowParameters.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using FurnitureFactoryBusinessLogic.OfficePackage.HelperEnums; + +namespace FurnitureFactoryBusinessLogic.OfficePackage.HelperEnums +{ + internal class PdfRowParameters + { + public List Texts { get; set; } = new(); + + public string Style { get; set; } = string.Empty; + + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs index 171b5f4..0f22889 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums +namespace FurnitureFactoryBusinessLogic.OfficePackage.HelperEnums { public enum WordJustificationType { diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs new file mode 100644 index 0000000..7d55216 --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using FurnitureFactoryBusinessLogic.OfficePackage.HelperEnums; + +namespace FurnitureFactoryBusinessLogic.OfficePackage.HelperModels +{ + internal class ExcelCellParameters + { + public string ColumnName { get; set; } = string.Empty; + + public uint RowIndex { get; set; } + + public string Text { get; set; } = string.Empty; + + public string CellReference => $"{ColumnName}{RowIndex}"; + + public ExcelStyleInfoType StyleInfo { get; set; } + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfoManager.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfoManager.cs index 9406da1..dd7a952 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfoManager.cs +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfoManager.cs @@ -4,6 +4,10 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using FurnitureContracts.ViewModel; +using FurnitureFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; namespace FurnitureFactoryBusinessLogic.OfficePackage.HelperModels { @@ -13,6 +17,6 @@ namespace FurnitureFactoryBusinessLogic.OfficePackage.HelperModels public string Title { get; set; } = string.Empty; - public List InterestLessons { get; set; } = new(); + public List SalesSalonsFurniture { get; set; } = new(); } } diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs new file mode 100644 index 0000000..cf2a426 --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureFactoryBusinessLogic.OfficePackage.HelperEnums +{ + internal class ExcelMergeParameters + { + public string CellFromName { get; set; } = string.Empty; + + public string CellToName { get; set; } = string.Empty; + + public string Merge => $"{CellFromName}:{CellToName}"; + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelStyleInfoType.cs similarity index 78% rename from FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs rename to FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelStyleInfoType.cs index 213d87e..cd4f6d9 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelStyleInfoType.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums +namespace FurnitureFactoryBusinessLogic.OfficePackage.HelperEnums { public enum ExcelStyleInfoType { diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/PdfInfoManager.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/PdfInfoManager.cs new file mode 100644 index 0000000..6c58c2a --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/PdfInfoManager.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using FurnitureContracts.ViewModel; + +namespace FurnitureFactoryBusinessLogic.OfficePackage.HelperModels +{ + public class PdfInfoManager + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public DateTime Date { get; set; } + + public List SalesSalons { get; set; } = new(); + + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/WordInfoManager.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/WordInfoManager.cs new file mode 100644 index 0000000..cbdb111 --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/WordInfoManager.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using FurnitureContracts.ViewModel; + +namespace FurnitureFactoryBusinessLogic.OfficePackage.HelperModels +{ + internal class WordInfoManager + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public List SalesSalonsFurniture { get; set; } = new(); + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs new file mode 100644 index 0000000..aa793b0 --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs @@ -0,0 +1,18 @@ +using FurnitureFactoryBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureFactoryBusinessLogic.OfficePackage.HelperModels +{ + internal class WordTextProperties + { + public string Size { get; set; } = string.Empty; + + public bool Bold { get; set; } + + public WordJustificationType JustificationType { get; set; } + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/AbstractSaveToPdfManager.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/AbstractSaveToPdfManager.cs new file mode 100644 index 0000000..8588319 --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/AbstractSaveToPdfManager.cs @@ -0,0 +1,75 @@ +using FurnitureFactoryBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using FurnitureFactoryBusinessLogic.OfficePackage.HelperEnums; +using FurnitureFactoryBusinessLogic.OfficePackage.HelperModels; + +namespace FurnitureFactoryBusinessLogic.OfficePackage.Implements +{ + internal class AbstractSaveToPdfManager + { + public void CreateDoc(PdfInfoManager info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + //CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + CreateTable(new List { "2cm", "3cm", "6cm", "3cm", "3cm", "6cm", "6cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List { "Интерес", "Изделие", "Дата", "Поделка", "Дата" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var interest in info.SalesSalons) + { + CreateRow(new PdfRowParameters + { + Texts = new List { interest.InterestTitle, interest.ProductTitle, interest.DateCreateProduct.ToShortDateString(), interest.DiyTitle, interest.DateCreateDiy.ToShortDateString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + + + SavePdf(info); + } + + /// + /// Создание doc-файла + /// + /// + protected abstract void CreatePdf(PdfInfoStudent info); + + /// + /// Создание параграфа с текстом + /// + /// + /// + protected abstract void CreateParagraph(PdfParagraph paragraph); + + /// + /// Создание таблицы + /// + /// + /// + protected abstract void CreateTable(List columns); + + /// + /// Создание и заполнение строки + /// + /// + protected abstract void CreateRow(PdfRowParameters rowParameters); + + /// + /// Сохранение файла + /// + /// + protected abstract void SavePdf(PdfInfoStudent info); + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/SaveToExcelManager.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/SaveToExcelManager.cs new file mode 100644 index 0000000..0a83c18 --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/SaveToExcelManager.cs @@ -0,0 +1,293 @@ +using FurnitureFactoryBusinessLogic.OfficePackage.HelperEnums; +using FurnitureFactoryBusinessLogic.OfficePackage.HelperModels; +using static System.Net.Mime.MediaTypeNames; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Office2010.Excel; +using DocumentFormat.OpenXml.Office2013.Excel; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; + + +namespace FurnitureFactoryBusinessLogic.OfficePackage.Implements +{ + internal class SaveToExcelManager + { + private SpreadsheetDocument? _spreadsheetDocument; + + private SharedStringTablePart? _shareStringPart; + + private Worksheet? _worksheet; + + /// + /// Настройка стилей для файла + /// + /// + private static void CreateStyles(WorkbookPart workbookpart) + { + var sp = workbookpart.AddNewPart(); + sp.Stylesheet = new Stylesheet(); + + var fonts = new Fonts() { Count = 2U, KnownFonts = true }; + + var fontUsual = new Font(); + fontUsual.Append(new FontSize() { Val = 12D }); + fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + fontUsual.Append(new FontName() { Val = "Times New Roman" }); + fontUsual.Append(new FontFamilyNumbering() { Val = 2 }); + fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + + var fontTitle = new Font(); + fontTitle.Append(new Bold()); + fontTitle.Append(new FontSize() { Val = 14D }); + fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + fontTitle.Append(new FontName() { Val = "Times New Roman" }); + fontTitle.Append(new FontFamilyNumbering() { Val = 2 }); + fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + + fonts.Append(fontUsual); + fonts.Append(fontTitle); + + var fills = new Fills() { Count = 2U }; + + var fill1 = new Fill(); + fill1.Append(new PatternFill() { PatternType = PatternValues.None }); + + var fill2 = new Fill(); + fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 }); + + fills.Append(fill1); + fills.Append(fill2); + + var borders = new Borders() { Count = 2U }; + + var borderNoBorder = new Border(); + borderNoBorder.Append(new LeftBorder()); + borderNoBorder.Append(new RightBorder()); + borderNoBorder.Append(new TopBorder()); + borderNoBorder.Append(new BottomBorder()); + borderNoBorder.Append(new DiagonalBorder()); + + var borderThin = new Border(); + + var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin }; + leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + var rightBorder = new RightBorder() { Style = BorderStyleValues.Thin }; + rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + var topBorder = new TopBorder() { Style = BorderStyleValues.Thin }; + topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + var bottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin }; + bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + borderThin.Append(leftBorder); + borderThin.Append(rightBorder); + borderThin.Append(topBorder); + borderThin.Append(bottomBorder); + borderThin.Append(new DiagonalBorder()); + + borders.Append(borderNoBorder); + borders.Append(borderThin); + + var cellStyleFormats = new CellStyleFormats() { Count = 1U }; + var cellFormatStyle = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U }; + + cellStyleFormats.Append(cellFormatStyle); + + var cellFormats = new CellFormats() { Count = 3U }; + var cellFormatFont = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U, FormatId = 0U, ApplyFont = true }; + var cellFormatFontAndBorder = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 1U, FormatId = 0U, ApplyFont = true, ApplyBorder = true }; + var cellFormatTitle = new CellFormat() { NumberFormatId = 0U, FontId = 1U, FillId = 0U, BorderId = 0U, FormatId = 0U, Alignment = new Alignment() { Vertical = VerticalAlignmentValues.Center, WrapText = true, Horizontal = HorizontalAlignmentValues.Center }, ApplyFont = true }; + + cellFormats.Append(cellFormatFont); + cellFormats.Append(cellFormatFontAndBorder); + cellFormats.Append(cellFormatTitle); + + var cellStyles = new CellStyles() { Count = 1U }; + + cellStyles.Append(new CellStyle() { Name = "Normal", FormatId = 0U, BuiltinId = 0U }); + + var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() { Count = 0U }; + + var tableStyles = new TableStyles() { Count = 0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" }; + + var stylesheetExtensionList = new StylesheetExtensionList(); + + var stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; + stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); + stylesheetExtension1.Append(new SlicerStyles() { DefaultSlicerStyle = "SlicerStyleLight1" }); + + var stylesheetExtension2 = new StylesheetExtension() { Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" }; + stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); + stylesheetExtension2.Append(new TimelineStyles() { DefaultTimelineStyle = "TimeSlicerStyleLight1" }); + + stylesheetExtensionList.Append(stylesheetExtension1); + stylesheetExtensionList.Append(stylesheetExtension2); + + sp.Stylesheet.Append(fonts); + sp.Stylesheet.Append(fills); + sp.Stylesheet.Append(borders); + sp.Stylesheet.Append(cellStyleFormats); + sp.Stylesheet.Append(cellFormats); + sp.Stylesheet.Append(cellStyles); + sp.Stylesheet.Append(differentialFormats); + sp.Stylesheet.Append(tableStyles); + sp.Stylesheet.Append(stylesheetExtensionList); + } + + /// + /// Получение номера стиля из типа + /// + /// + /// + private static uint GetStyleValue(ExcelStyleInfoType styleInfo) + { + return styleInfo switch + { + ExcelStyleInfoType.Title => 2U, + ExcelStyleInfoType.TextWithBroder => 1U, + ExcelStyleInfoType.Text => 0U, + _ => 0U, + }; + } + + protected override void CreateExcel(ExcelInfoStudent info) + { + _spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook); + + var workbookpart = _spreadsheetDocument.AddWorkbookPart(); + workbookpart.Workbook = new Workbook(); + + CreateStyles(workbookpart); + + + _shareStringPart = _spreadsheetDocument.WorkbookPart!.GetPartsOfType().Any() + ? _spreadsheetDocument.WorkbookPart.GetPartsOfType().First() + : _spreadsheetDocument.WorkbookPart.AddNewPart(); + + + if (_shareStringPart.SharedStringTable == null) + { + _shareStringPart.SharedStringTable = new SharedStringTable(); + } + + + var worksheetPart = workbookpart.AddNewPart(); + worksheetPart.Worksheet = new Worksheet(new SheetData()); + + + var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets()); + var sheet = new Sheet() + { + Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), + SheetId = 1, + Name = "Лист" + }; + sheets.Append(sheet); + + _worksheet = worksheetPart.Worksheet; + } + + protected override void InsertCellInWorksheet(ExcelCellParameters excelParams) + { + if (_worksheet == null || _shareStringPart == null) + { + return; + } + var sheetData = _worksheet.GetFirstChild(); + if (sheetData == null) + { + return; + } + + + Row row; + if (sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).Any()) + { + row = sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).First(); + } + else + { + row = new Row() { RowIndex = excelParams.RowIndex }; + sheetData.Append(row); + } + + + Cell cell; + if (row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).Any()) + { + cell = row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).First(); + } + else + { + + Cell? refCell = null; + foreach (Cell rowCell in row.Elements()) + { + if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0) + { + refCell = rowCell; + break; + } + } + + var newCell = new Cell() { CellReference = excelParams.CellReference }; + row.InsertBefore(newCell, refCell); + + cell = newCell; + } + + + _shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text))); + _shareStringPart.SharedStringTable.Save(); + + cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements().Count() - 1).ToString()); + cell.DataType = new EnumValue(CellValues.SharedString); + cell.StyleIndex = GetStyleValue(excelParams.StyleInfo); + } + + protected override void MergeCells(ExcelMergeParameters excelParams) + { + if (_worksheet == null) + { + return; + } + MergeCells mergeCells; + + if (_worksheet.Elements().Any()) + { + mergeCells = _worksheet.Elements().First(); + } + else + { + mergeCells = new MergeCells(); + + if (_worksheet.Elements().Any()) + { + _worksheet.InsertAfter(mergeCells, _worksheet.Elements().First()); + } + else + { + _worksheet.InsertAfter(mergeCells, _worksheet.Elements().First()); + } + } + + var mergeCell = new MergeCell() + { + Reference = new StringValue(excelParams.Merge) + }; + mergeCells.Append(mergeCell); + } + + protected override void SaveExcel(ExcelInfoManager info) + { + if (_spreadsheetDocument == null) + { + return; + } + _spreadsheetDocument.WorkbookPart!.Workbook.Save(); + _spreadsheetDocument.Close(); + } + } +}