diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs index a48f537..004ae2a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -37,7 +37,7 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage } }); } - SaveWord(info); + SaveWord(info); } public void CreateDocStores(WordInfo info) { @@ -54,25 +54,39 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage JustificationType = WordJustificationType.Center } }); - foreach (var store in info.Stores) + //foreach (var store in info.Stores) + //{ + // CreateParagraph(new WordParagraph + // { + // Texts = new List<(string, WordTextProperties)> + // { + // (store.StoreName, new WordTextProperties { Bold = true, Size = "24", }), + // (" ", new WordTextProperties { Size = "24"}), + // (store.Address, new WordTextProperties { Size = "24" }), + // (" ", new WordTextProperties { Size = "24"}), + // (store.OpeningDate.ToShortDateString(), new WordTextProperties { Size = "24" }) + // }, + // TextProperties = new WordTextProperties + // { + // Size = "24", + // JustificationType = WordJustificationType.Both + // } + // }); + //} + CreateTable(new() { - CreateParagraph(new WordParagraph - { - Texts = new List<(string, WordTextProperties)> - { - (store.StoreName, new WordTextProperties { Bold = true, Size = "24", }), - (" ", new WordTextProperties { Size = "24"}), - (store.Address, new WordTextProperties { Size = "24" }), - (" ", new WordTextProperties { Size = "24"}), - (store.OpeningDate.ToShortDateString(), new WordTextProperties { Size = "24" }) - }, - TextProperties = new WordTextProperties - { - Size = "24", - JustificationType = WordJustificationType.Both - } - }); - } + ("Название", 3000), + ("Дата", null), + ("Адрес открытия", 4500), + }, + info.Stores + .Select(x => new List + { + x.StoreName, + Convert.ToString(x.OpeningDate.ToShortDateString), + x.Address, + }) + .ToList()); SaveWord(info); } /// @@ -91,6 +105,6 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage /// /// protected abstract void SaveWord(WordInfo info); - - } + protected abstract void CreateTable(List<(string, int?)> nameAndWidthColumns, List> rows); + } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs index aaae522..b4900a5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -117,5 +117,43 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage.Implements _wordDocument.MainDocumentPart!.Document.Save(); _wordDocument.Close(); } - } + private static TableCell GetTableCell(string text, int? widthCell = null) + { + + TableCell cell = new(new Paragraph(new Run(new Text(text)))); + if (widthCell != null) + { + cell.Append(new TableCellProperties() + { + TableCellWidth = new() { Width = widthCell.ToString() } + }); + } + return cell; + } + protected override void CreateTable(List<(string, int?)> nameAndWidthColumns, List> rows) + { + if (_docBody == null) + { + return; + } + Table table = new(); + TableProperties tblProp = new TableProperties( + new TableBorders( + new TopBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new BottomBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new LeftBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new RightBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new InsideHorizontalBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new InsideVerticalBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 } + ) + ); + table.AppendChild(tblProp); + + table.Append(new TableRow(nameAndWidthColumns.Select(x => GetTableCell(x.Item1, x.Item2)))); + + table.Append(rows.Select(x => new TableRow(x.Select(y => GetTableCell(y))))); + + _docBody.Append(table); + } + } }