From 503c88533b9815b677fbe78323275caa9284a2b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Tue, 9 May 2023 18:53:32 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BF=D0=BE=20=D0=B2=D0=BE=D1=80=D0=B4=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OfficePackage/AbstractSaveToWord.cs | 56 ++++++++++++------- .../OfficePackage/Implements/SaveToWord.cs | 40 ++++++++++++- 2 files changed, 74 insertions(+), 22 deletions(-) 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); + } + } }