From 0afe8a7682f3688cf0764bf16e8346f25f73bdef Mon Sep 17 00:00:00 2001 From: kotcheshir73 Date: Sat, 17 Dec 2022 23:44:29 +0400 Subject: [PATCH] ToolsOffice word --- .../WordOpenXML/BuilderWordDocumentOpenXML.cs | 76 +++ .../Extenstions/WordDocumentExtenstion.cs | 516 ++++++++++++++++++ .../WordOpenXML/Models/WordCreateDocument.cs | 9 + .../WordOpenXML/Models/WordDocumentParts.cs | 17 + .../Models/WordDocumentSettings.cs | 26 + .../Models/WordJustificationType.cs | 13 + .../Models/WordPageOrientationType.cs | 12 + .../WordOpenXML/Models/WordParagraph.cs | 12 + .../Models/WordParagraphProperties.cs | 31 ++ .../Implements/WordOpenXML/Models/WordRun.cs | 13 + .../WordOpenXML/Models/WordRunProperties.cs | 15 + .../WordOpenXML/Models/WordSaveDocument.cs | 9 + .../WordOpenXML/Models/WordTable.cs | 14 + .../WordOpenXML/Models/WordTableBorder.cs | 15 + .../WordOpenXML/Models/WordTableBorderType.cs | 21 + .../WordOpenXML/Models/WordTableCell.cs | 11 + .../Models/WordTableCellProperties.cs | 13 + .../WordOpenXML/Models/WordTableGrid.cs | 10 + .../WordOpenXML/Models/WordTableProperties.cs | 31 ++ .../WordOpenXML/Models/WordTableRow.cs | 11 + .../Models/WordTableRowProperties.cs | 11 + .../Interfaces/Word/BuilderWordDocument.cs | 32 ++ .../Word/Models/ICreateWordModel.cs | 4 + .../Word/Models/IParagraphWordModel.cs | 4 + .../Interfaces/Word/Models/ISaveWordModel.cs | 4 + .../Interfaces/Word/Models/ITableWordModel.cs | 4 + .../Common/ToolsOffice/ToolsOffice.csproj | 15 + DepartmentPortal/DepartmentPortal.sln | 9 +- 28 files changed, 957 insertions(+), 1 deletion(-) create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/BuilderWordDocumentOpenXML.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extenstions/WordDocumentExtenstion.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordCreateDocument.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordDocumentParts.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordDocumentSettings.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordJustificationType.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordPageOrientationType.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordParagraph.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordParagraphProperties.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordRun.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordRunProperties.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordSaveDocument.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTable.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableBorder.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableBorderType.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableCell.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableCellProperties.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableGrid.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableProperties.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableRow.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableRowProperties.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Interfaces/Word/BuilderWordDocument.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ICreateWordModel.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/IParagraphWordModel.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ISaveWordModel.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ITableWordModel.cs create mode 100644 DepartmentPortal/Common/ToolsOffice/ToolsOffice.csproj diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/BuilderWordDocumentOpenXML.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/BuilderWordDocumentOpenXML.cs new file mode 100644 index 0000000..a998b36 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/BuilderWordDocumentOpenXML.cs @@ -0,0 +1,76 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using System.IO; +using ToolsOffice.Implements.WordOpenXML.Extenstions; +using ToolsOffice.Implements.WordOpenXML.Models; +using ToolsOffice.Interfaces.Word; +using ToolsOffice.Interfaces.Word.Models; + +namespace ToolsOffice.Implements.WordOpenXML +{ + public class BuilderWordDocumentOpenXML : BuilderWordDocument + { + private WordprocessingDocument _wordDocument; + + private Body _docBody; + + private MemoryStream _memoryStream; + + public override void CreateDocument(ICreateWordModel model) + { + _memoryStream = new MemoryStream(); + _wordDocument = WordprocessingDocument.Create(_memoryStream, WordprocessingDocumentType.Document); + var mainPart = _wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); + _docBody = mainPart.Document.AppendChild(new Body()); + if (model is WordCreateDocument document) + { + mainPart.AddParts(document.WordDocumentParts); + } + } + + public override void CreateParagraph(IParagraphWordModel model) + { + if (model is WordParagraph paragraph) + { + var docParagraph = new Paragraph(); + docParagraph.AddParagraphProperties(paragraph.ParagraphProperties); + foreach (var run in paragraph.Texts) + { + docParagraph.AddRun(run); + } + _docBody.AppendChild(docParagraph); + } + } + + public override void CreateTable(ITableWordModel model) + { + if (model is WordTable table) + { + var docTable = new Table(); + + docTable.AddTableProperties(table.TableProperties); + + docTable.AddGridColumn(table.TableGrid); + + foreach (var row in table.Rows) + { + docTable.AddTableRow(row); + } + _docBody.AppendChild(docTable); + } + } + + public override Stream SaveDocument(ISaveWordModel info) + { + if (info is WordSaveDocument document) + { + _docBody.AddSectionProperties(document); + } + _wordDocument.MainDocumentPart.Document.Save(); + _wordDocument.Close(); + return _memoryStream; + } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extenstions/WordDocumentExtenstion.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extenstions/WordDocumentExtenstion.cs new file mode 100644 index 0000000..c31f2f8 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extenstions/WordDocumentExtenstion.cs @@ -0,0 +1,516 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using System; +using ToolsModule.ManagmentExtension; +using ToolsOffice.Implements.WordOpenXML.Models; + +namespace ToolsOffice.Implements.WordOpenXML.Extenstions +{ + public static class WordDocumentExtenstion + { + /// + /// Добавление общих элементов документа + /// + /// + /// + public static void AddParts(this MainDocumentPart mainPart, WordDocumentParts parts) + { + if (parts == null) + { + return; + } + CreateDocumentSettingsPart(parts, mainPart); + CreateFontTablesPart(parts, mainPart); + CreateNumberingsPart(parts, mainPart); + CreateStyleDefinitionsPart(parts, mainPart); + CreateThemePart(parts, mainPart); + CreateWebSetting(parts, mainPart); + } + + /// + /// Добавление общих настроек документа + /// + /// + /// + public static void AddSectionProperties(this Body body, WordSaveDocument document) + { + if (document == null || document.DocumentSettings == null) + { + return; + } + + var properties = new SectionProperties(); + + var pageSize = new PageSize(); + if (document.DocumentSettings.PageSizeHeight != null) + { + pageSize.Height = document.DocumentSettings.PageSizeHeight; + } + if (document.DocumentSettings.PageSizeWidth != null) + { + pageSize.Width = document.DocumentSettings.PageSizeWidth; + } + if (document.DocumentSettings.WordPageOrientation.HasValue) + { + pageSize.Orient = (PageOrientationValues)Enum.Parse(typeof(PageOrientationValues), document.DocumentSettings.WordPageOrientation.Value.ToString()); + } + properties.AppendChild(pageSize); + + var pageMargin = new PageMargin(); + if (document.DocumentSettings.PageMarginBottom.HasValue) + { + pageMargin.Bottom = document.DocumentSettings.PageMarginBottom.Value; + } + if (document.DocumentSettings.PageMarginFooter != null) + { + pageMargin.Footer = document.DocumentSettings.PageMarginFooter; + } + if (document.DocumentSettings.PageMarginGutter != null) + { + pageMargin.Gutter = document.DocumentSettings.PageMarginGutter; + } + if (document.DocumentSettings.PageMarginLeft != null) + { + pageMargin.Left = document.DocumentSettings.PageMarginLeft; + } + if (document.DocumentSettings.PageMarginRight != null) + { + pageMargin.Right = document.DocumentSettings.PageMarginRight; + } + if (document.DocumentSettings.PageMarginTop.HasValue) + { + pageMargin.Top = document.DocumentSettings.PageMarginTop.Value; + } + properties.AppendChild(pageMargin); + + body.AppendChild(properties); + } + + /// + /// Добавление свойств абзаца + /// + /// + /// + public static void AddParagraphProperties(this Paragraph paragraph, WordParagraphProperties wordProperties) + { + if (wordProperties == null) + { + return; + } + var properties = new ParagraphProperties(); + + if (wordProperties.JustificationType.HasValue) + { + var justification = new Justification() + { + Val = (JustificationValues)Enum.Parse(typeof(JustificationValues), wordProperties.JustificationType.Value.ToString()) + }; + properties.AppendChild(justification); + } + + var spacingBetweenLines = new SpacingBetweenLines(); + if (wordProperties.SpacingBetweenLinesLine != null) + { + spacingBetweenLines.Line = wordProperties.SpacingBetweenLinesLine; + } + if (wordProperties.SpacingBetweenLinesBefore != null) + { + spacingBetweenLines.Before = wordProperties.SpacingBetweenLinesBefore; + } + if (wordProperties.SpacingBetweenLinesAfter != null) + { + spacingBetweenLines.After = wordProperties.SpacingBetweenLinesAfter; + } + properties.AppendChild(spacingBetweenLines); + + var indentation = new Indentation(); + if (wordProperties.IndentationFirstLine != null) + { + indentation.FirstLine = wordProperties.IndentationFirstLine; + } + if (wordProperties.IndentationHanging != null) + { + indentation.Hanging = wordProperties.IndentationHanging; + } + if (wordProperties.IndentationLeft != null) + { + indentation.Left = wordProperties.IndentationLeft; + } + if (wordProperties.IndentationRight != null) + { + indentation.Right = wordProperties.IndentationRight; + } + properties.AppendChild(indentation); + + var paragraphMarkRunProperties = new ParagraphMarkRunProperties(); + if (wordProperties.Size != null) + { + paragraphMarkRunProperties.AppendChild(new FontSize { Val = wordProperties.Size }); + } + if (wordProperties.IsBold) + { + paragraphMarkRunProperties.AppendChild(new Bold()); + } + if (wordProperties.IsItalic) + { + paragraphMarkRunProperties.AppendChild(new Italic()); + } + if (wordProperties.IsUnderline) + { + paragraphMarkRunProperties.AppendChild(new Underline()); + } + properties.AppendChild(paragraphMarkRunProperties); + + paragraph.AppendChild(properties); + } + + /// + /// Добавление текста в абзац + /// + /// + /// + /// + public static void AddRun(this Paragraph paragraph, WordRun run) + { + if (run == null) + { + return; + } + var docRun = new Run(); + + docRun.AddRunProperties(run.RunProperties); + + if (run.IsBreak) + { + docRun.AppendChild(new Break()); + } + else if (run.IsTabChar) + { + docRun.AppendChild(new TabChar()); + } + else + { + docRun.AppendChild(new Text { Text = run.Text, Space = SpaceProcessingModeValues.Preserve }); + } + + paragraph.AppendChild(docRun); + } + + public static void AddTableProperties(this Table table, WordTableProperties wordTableProperties) + { + if (wordTableProperties == null) + { + return; + } + + var properties = new TableProperties(); + + if (wordTableProperties.Width != null) + { + properties.AppendChild(new TableWidth() { Width = wordTableProperties.Width }); + } + + var tableLook = new TableLook(); + if (wordTableProperties.LookValue != null) + { + tableLook.Val = wordTableProperties.LookValue; + } + if (wordTableProperties.LookFirstRow) + { + tableLook.FirstRow = new OnOffValue(wordTableProperties.LookFirstRow); + } + if (wordTableProperties.LookFirstColumn) + { + tableLook.FirstColumn = new OnOffValue(wordTableProperties.LookFirstColumn); + } + if (wordTableProperties.LookLastRow) + { + tableLook.LastRow = new OnOffValue(wordTableProperties.LookLastRow); + } + if (wordTableProperties.LookLastColumn) + { + tableLook.LastColumn = new OnOffValue(wordTableProperties.LookLastColumn); + } + if (wordTableProperties.LookNoHorizontalBand) + { + tableLook.NoHorizontalBand = new OnOffValue(wordTableProperties.LookNoHorizontalBand); + } + if (wordTableProperties.LookNoVerticalBand) + { + tableLook.NoVerticalBand = new OnOffValue(wordTableProperties.LookNoVerticalBand); + } + properties.AppendChild(tableLook); + + var tableBorders = new TableBorders(); + + tableBorders.AddBorder(wordTableProperties.TopBorder, new TopBorder()); + tableBorders.AddBorder(wordTableProperties.BottomBorder, new BottomBorder()); + tableBorders.AddBorder(wordTableProperties.LeftBorder, new LeftBorder()); + tableBorders.AddBorder(wordTableProperties.RightBorder, new RightBorder()); + + properties.AppendChild(tableBorders); + + table.AppendChild(properties); + } + + public static void AddGridColumn(this Table table, WordTableGrid wordTableGrid) + { + if (wordTableGrid == null || wordTableGrid.Widths == null || wordTableGrid.Widths.Count == 0) + { + return; + } + var tableGrid = new TableGrid(); + foreach (var grid in wordTableGrid.Widths) + { + tableGrid.AppendChild(new GridColumn() { Width = grid }); + } + table.AppendChild(tableGrid); + } + + public static void AddTableRow(this Table table, WordTableRow row) + { + if (row == null) + { + return; + } + var docRow = new TableRow(); + + docRow.AddTableRowProperties(row.RowProperties); + + foreach (var cell in row.Cells) + { + docRow.AddTableCell(cell); + } + table.AppendChild(docRow); + } + + /// + /// Добавление свойств текста + /// + /// + /// + private static void AddRunProperties(this Run run, WordRunProperties wordProperties) + { + if (wordProperties == null) + { + return; + } + + if (wordProperties.Size != null || wordProperties.IsBold || wordProperties.IsItalic || wordProperties.IsUnderline) + { + var properties = new RunProperties(); + if (wordProperties.Size != null) + { + properties.AppendChild(new FontSize { Val = wordProperties.Size }); + } + if (wordProperties.IsBold) + { + properties.AppendChild(new Bold()); + } + if (wordProperties.IsItalic) + { + properties.AppendChild(new Italic()); + } + if (wordProperties.IsUnderline) + { + properties.AppendChild(new Underline()); + } + + run.AppendChild(properties); + } + } + + private static void AddBorder(this TableBorders tableBorders, WordTableBorder wordTableBorder, BorderType borderType) + { + if (wordTableBorder == null) + { + return; + } + if (wordTableBorder.BorderType.HasValue) + { + borderType.Val = (BorderValues)Enum.Parse(typeof(BorderValues), wordTableBorder.BorderType.Value.ToString()); + } + if (wordTableBorder.Color != null) + { + borderType.Color = wordTableBorder.Color; + } + if (wordTableBorder.Size != null) + { + borderType.Size = wordTableBorder.Size; + } + if (wordTableBorder.Space != null) + { + borderType.Space = wordTableBorder.Space; + } + tableBorders.AppendChild(borderType); + } + + private static void AddTableRowProperties(this TableRow row, WordTableRowProperties wordTableRowProperties) + { + if (wordTableRowProperties == null) + { + return; + } + + if (wordTableRowProperties.CantSplit.HasValue || wordTableRowProperties.TableRowHeight != null) + { + var properties = new TableRowProperties(); + + if (wordTableRowProperties.CantSplit.HasValue) + { + properties.AppendChild(new CantSplit() { Val = wordTableRowProperties.CantSplit.Value ? OnOffOnlyValues.On : OnOffOnlyValues.Off }); + } + + if (wordTableRowProperties.TableRowHeight != null) + { + properties.AppendChild(new TableRowHeight() { Val = wordTableRowProperties.TableRowHeight }); + } + + row.AppendChild(properties); + } + } + + private static void AddTableCell(this TableRow row, WordTableCell cell) + { + if (cell == null) + { + return; + } + var docCell = new TableCell(); + docCell.AddTableCellProperties(cell.CellProperties); + foreach (var paragraph in cell.Paragraphs) + { + docCell.AddParagraph(paragraph); + } + row.AppendChild(docCell); + } + + private static void AddTableCellProperties(this TableCell cell, WordTableCellProperties wordTableCellProperties) + { + if (wordTableCellProperties == null) + { + return; + } + + var properties = new TableCellProperties(); + if (wordTableCellProperties.TableCellWidth != null) + { + properties.AppendChild(new TableCellWidth() { Width = wordTableCellProperties.TableCellWidth }); + } + if (wordTableCellProperties.GridSpan != null) + { + properties.AppendChild(new GridSpan() { Val = wordTableCellProperties.GridSpan }); + } + if (wordTableCellProperties.MergeType.HasValue) + { + if (wordTableCellProperties.MergeType.Value) + { + properties.AppendChild(new VerticalMerge() + { + Val = MergedCellValues.Restart + }); + } + else + { + properties.AppendChild(new VerticalMerge()); + } + } + + cell.AppendChild(properties); + } + + private static void AddParagraph(this TableCell cell, WordParagraph paragraph) + { + if (paragraph == null) + { + return; + } + var docParagraph = new Paragraph(); + docParagraph.AddParagraphProperties(paragraph.ParagraphProperties); + foreach (var run in paragraph.Texts) + { + docParagraph.AddRun(run); + } + cell.AppendChild(docParagraph); + } + + private static void CreateDocumentSettingsPart(WordDocumentParts parts, MainDocumentPart mainPart) + { + if (parts.DocumentSettings.IsNotEmpty()) + { + var settings = mainPart.AddNewPart(); + settings.Settings = new Settings + { + InnerXml = parts.DocumentSettings + }; + settings.Settings.Save(); + } + } + + private static void CreateFontTablesPart(WordDocumentParts parts, MainDocumentPart mainPart) + { + if (parts.FontTable.IsNotEmpty()) + { + var fonts = mainPart.AddNewPart(); + fonts.Fonts = new Fonts + { + InnerXml = parts.FontTable + }; + fonts.Fonts.Save(); + } + } + + private static void CreateNumberingsPart(WordDocumentParts parts, MainDocumentPart mainPart) + { + if (parts.NumberingDefinitions.IsNotEmpty()) + { + var numbering = mainPart.AddNewPart(); + numbering.Numbering = new Numbering + { + InnerXml = parts.NumberingDefinitions + }; + numbering.Numbering.Save(); + } + } + + private static void CreateStyleDefinitionsPart(WordDocumentParts parts, MainDocumentPart mainPart) + { + if (parts.StyleDefinitions.IsNotEmpty()) + { + var styles = mainPart.AddNewPart(); + styles.Styles = new Styles + { + InnerXml = parts.StyleDefinitions + }; + styles.Styles.Save(); + } + } + + private static void CreateThemePart(WordDocumentParts parts, MainDocumentPart mainPart) + { + if (parts.Theme.IsNotEmpty()) + { + var thems = mainPart.AddNewPart(); + thems.Theme = new DocumentFormat.OpenXml.Drawing.Theme + { + InnerXml = parts.Theme + }; + thems.Theme.Save(); + } + } + + private static void CreateWebSetting(WordDocumentParts parts, MainDocumentPart mainPart) + { + if (parts.WebSettings.IsNotEmpty()) + { + var settings = mainPart.AddNewPart(); + settings.WebSettings = new WebSettings + { + InnerXml = parts.WebSettings + }; + settings.WebSettings.Save(); + } + } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordCreateDocument.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordCreateDocument.cs new file mode 100644 index 0000000..76def18 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordCreateDocument.cs @@ -0,0 +1,9 @@ +using ToolsOffice.Interfaces.Word.Models; + +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + public class WordCreateDocument : ICreateWordModel + { + public WordDocumentParts WordDocumentParts { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordDocumentParts.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordDocumentParts.cs new file mode 100644 index 0000000..47bfcfb --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordDocumentParts.cs @@ -0,0 +1,17 @@ +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + public class WordDocumentParts + { + public string DocumentSettings { get; set; } + + public string FontTable { get; set; } + + public string NumberingDefinitions { get; set; } + + public string StyleDefinitions { get; set; } + + public string Theme { get; set; } + + public string WebSettings { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordDocumentSettings.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordDocumentSettings.cs new file mode 100644 index 0000000..371bb13 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordDocumentSettings.cs @@ -0,0 +1,26 @@ +using DocumentFormat.OpenXml; + +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + public class WordDocumentSettings + { + public UInt32Value PageSizeHeight { get; set; } + + public UInt32Value PageSizeWidth { get; set; } + + public WordPageOrientationType? WordPageOrientation { get; set; } + + + public UInt32Value PageMarginFooter { get; set; } + + public UInt32Value PageMarginGutter { get; set; } + + public int? PageMarginBottom { get; set; } + + public int? PageMarginTop { get; set; } + + public UInt32Value PageMarginLeft { get; set; } + + public UInt32Value PageMarginRight { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordJustificationType.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordJustificationType.cs new file mode 100644 index 0000000..04fb33b --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordJustificationType.cs @@ -0,0 +1,13 @@ +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + public enum WordJustificationType + { + Left = 0, + + Center = 2, + + Right = 3, + + Both = 5 + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordPageOrientationType.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordPageOrientationType.cs new file mode 100644 index 0000000..b91c497 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordPageOrientationType.cs @@ -0,0 +1,12 @@ +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + /// + /// Ориентация страниц документа + /// + public enum WordPageOrientationType + { + Portrait = 0, + + Landscape = 1 + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordParagraph.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordParagraph.cs new file mode 100644 index 0000000..37fafb2 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordParagraph.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using ToolsOffice.Interfaces.Word.Models; + +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + public class WordParagraph : IParagraphWordModel + { + public List Texts { get; set; } + + public WordParagraphProperties ParagraphProperties { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordParagraphProperties.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordParagraphProperties.cs new file mode 100644 index 0000000..5b2a639 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordParagraphProperties.cs @@ -0,0 +1,31 @@ +using DocumentFormat.OpenXml; + +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + public class WordParagraphProperties + { + public StringValue Size { get; set; } + + public bool IsBold { get; set; } + + public bool IsItalic { get; set; } + + public bool IsUnderline { get; set; } + + public WordJustificationType? JustificationType { get; set; } + + public StringValue SpacingBetweenLinesLine { get; set; } + + public StringValue SpacingBetweenLinesBefore { get; set; } + + public StringValue SpacingBetweenLinesAfter { get; set; } + + public StringValue IndentationFirstLine { get; set; } + + public StringValue IndentationHanging { get; set; } + + public StringValue IndentationLeft { get; set; } + + public StringValue IndentationRight { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordRun.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordRun.cs new file mode 100644 index 0000000..19fc568 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordRun.cs @@ -0,0 +1,13 @@ +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + public class WordRun + { + public string Text { get; set; } + + public bool IsBreak { get; set; } + + public bool IsTabChar { get; set; } + + public WordRunProperties RunProperties { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordRunProperties.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordRunProperties.cs new file mode 100644 index 0000000..e97bad2 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordRunProperties.cs @@ -0,0 +1,15 @@ +using DocumentFormat.OpenXml; + +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + public class WordRunProperties + { + public StringValue Size { get; set; } + + public bool IsBold { get; set; } + + public bool IsItalic { get; set; } + + public bool IsUnderline { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordSaveDocument.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordSaveDocument.cs new file mode 100644 index 0000000..130aa39 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordSaveDocument.cs @@ -0,0 +1,9 @@ +using ToolsOffice.Interfaces.Word.Models; + +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + public class WordSaveDocument : ISaveWordModel + { + public WordDocumentSettings DocumentSettings { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTable.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTable.cs new file mode 100644 index 0000000..c59f691 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTable.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using ToolsOffice.Interfaces.Word.Models; + +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + public class WordTable : ITableWordModel + { + public WordTableProperties TableProperties { get; set; } + + public WordTableGrid TableGrid { get; set; } + + public List Rows { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableBorder.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableBorder.cs new file mode 100644 index 0000000..2f6b40d --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableBorder.cs @@ -0,0 +1,15 @@ +using DocumentFormat.OpenXml; + +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + public class WordTableBorder + { + public UInt32Value Size { get; set; } + + public UInt32Value Space { get; set; } + + public StringValue Color { get; set; } + + public WordTableBorderType? BorderType { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableBorderType.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableBorderType.cs new file mode 100644 index 0000000..5c21b88 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableBorderType.cs @@ -0,0 +1,21 @@ +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + public enum WordTableBorderType + { + None = 1, + + Single = 2, + + Thick = 3, + + Double = 4, + + Dotted = 5, + + Dashed = 6, + + DotDash = 7, + + DotDotDash = 8, + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableCell.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableCell.cs new file mode 100644 index 0000000..c19a171 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableCell.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + public class WordTableCell + { + public WordTableCellProperties CellProperties { get; set; } + + public List Paragraphs { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableCellProperties.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableCellProperties.cs new file mode 100644 index 0000000..392192c --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableCellProperties.cs @@ -0,0 +1,13 @@ +using DocumentFormat.OpenXml; + +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + public class WordTableCellProperties + { + public StringValue TableCellWidth { get; set; } + + public Int32Value GridSpan { get; set; } + + public bool? MergeType { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableGrid.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableGrid.cs new file mode 100644 index 0000000..ac4a5ed --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableGrid.cs @@ -0,0 +1,10 @@ +using DocumentFormat.OpenXml; +using System.Collections.Generic; + +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + public class WordTableGrid + { + public List Widths { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableProperties.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableProperties.cs new file mode 100644 index 0000000..fd5ee89 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableProperties.cs @@ -0,0 +1,31 @@ +using DocumentFormat.OpenXml; + +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + public class WordTableProperties + { + public StringValue Width { get; set; } + + public HexBinaryValue LookValue { get; set; } + + public bool LookFirstRow { get; set; } + + public bool LookFirstColumn { get; set; } + + public bool LookLastRow { get; set; } + + public bool LookLastColumn { get; set; } + + public bool LookNoHorizontalBand { get; set; } + + public bool LookNoVerticalBand { get; set; } + + public WordTableBorder TopBorder { get; set; } + + public WordTableBorder BottomBorder { get; set; } + + public WordTableBorder LeftBorder { get; set; } + + public WordTableBorder RightBorder { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableRow.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableRow.cs new file mode 100644 index 0000000..a21687c --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableRow.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + public class WordTableRow + { + public WordTableRowProperties RowProperties { get; set; } + + public List Cells { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableRowProperties.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableRowProperties.cs new file mode 100644 index 0000000..9220936 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableRowProperties.cs @@ -0,0 +1,11 @@ +using DocumentFormat.OpenXml; + +namespace ToolsOffice.Implements.WordOpenXML.Models +{ + public class WordTableRowProperties + { + public bool? CantSplit { get; set; } + + public UInt32Value TableRowHeight { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/BuilderWordDocument.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/BuilderWordDocument.cs new file mode 100644 index 0000000..661836d --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/BuilderWordDocument.cs @@ -0,0 +1,32 @@ +using System.IO; +using ToolsOffice.Interfaces.Word.Models; + +namespace ToolsOffice.Interfaces.Word +{ + public abstract class BuilderWordDocument + { + /// + /// Создание документа + /// + /// + public abstract void CreateDocument(ICreateWordModel model); + + /// + /// Создание абзаца с текстом + /// + /// + public abstract void CreateParagraph(IParagraphWordModel model); + + /// + /// Создание абзаца с текстом + /// + /// + public abstract void CreateTable(ITableWordModel model); + + /// + /// Сохранение файла + /// + /// + public abstract Stream SaveDocument(ISaveWordModel info); + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ICreateWordModel.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ICreateWordModel.cs new file mode 100644 index 0000000..009121e --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ICreateWordModel.cs @@ -0,0 +1,4 @@ +namespace ToolsOffice.Interfaces.Word.Models +{ + public interface ICreateWordModel { } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/IParagraphWordModel.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/IParagraphWordModel.cs new file mode 100644 index 0000000..1bdf6b3 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/IParagraphWordModel.cs @@ -0,0 +1,4 @@ +namespace ToolsOffice.Interfaces.Word.Models +{ + public interface IParagraphWordModel { } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ISaveWordModel.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ISaveWordModel.cs new file mode 100644 index 0000000..856273a --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ISaveWordModel.cs @@ -0,0 +1,4 @@ +namespace ToolsOffice.Interfaces.Word.Models +{ + public interface ISaveWordModel { } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ITableWordModel.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ITableWordModel.cs new file mode 100644 index 0000000..297c22c --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ITableWordModel.cs @@ -0,0 +1,4 @@ +namespace ToolsOffice.Interfaces.Word.Models +{ + public interface ITableWordModel { } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/ToolsOffice.csproj b/DepartmentPortal/Common/ToolsOffice/ToolsOffice.csproj new file mode 100644 index 0000000..2bff211 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/ToolsOffice.csproj @@ -0,0 +1,15 @@ + + + + net5.0 + + + + + + + + + + + diff --git a/DepartmentPortal/DepartmentPortal.sln b/DepartmentPortal/DepartmentPortal.sln index 2ed5003..2ee198f 100644 --- a/DepartmentPortal/DepartmentPortal.sln +++ b/DepartmentPortal/DepartmentPortal.sln @@ -37,7 +37,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DepartmentContract", "Depar EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WindowServices", "WindowServices", "{045965BC-9297-45DF-96E1-6986C286A81B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowServiceSyncStudentOrders", "WindowServices\WindowServiceSyncStudentOrders\WindowServiceSyncStudentOrders.csproj", "{4A68AC9F-07F9-43C3-83E6-359A9CFBC80E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WindowServiceSyncStudentOrders", "WindowServices\WindowServiceSyncStudentOrders\WindowServiceSyncStudentOrders.csproj", "{4A68AC9F-07F9-43C3-83E6-359A9CFBC80E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToolsOffice", "Common\ToolsOffice\ToolsOffice.csproj", "{782DE093-CE87-48B5-A037-47C2189ACC13}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -101,6 +103,10 @@ Global {4A68AC9F-07F9-43C3-83E6-359A9CFBC80E}.Debug|Any CPU.Build.0 = Debug|Any CPU {4A68AC9F-07F9-43C3-83E6-359A9CFBC80E}.Release|Any CPU.ActiveCfg = Release|Any CPU {4A68AC9F-07F9-43C3-83E6-359A9CFBC80E}.Release|Any CPU.Build.0 = Release|Any CPU + {782DE093-CE87-48B5-A037-47C2189ACC13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {782DE093-CE87-48B5-A037-47C2189ACC13}.Debug|Any CPU.Build.0 = Debug|Any CPU + {782DE093-CE87-48B5-A037-47C2189ACC13}.Release|Any CPU.ActiveCfg = Release|Any CPU + {782DE093-CE87-48B5-A037-47C2189ACC13}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -119,6 +125,7 @@ Global {E9F9B0D8-18F3-40C3-843F-53D2F8B2293E} = {7DA26C36-778E-4563-9AEC-966E26EA7B2A} {5AA4DBD9-FD82-46D6-8A62-78DB269296B3} = {A19E7709-6AD8-4E9B-B3AB-4339C67D9F39} {4A68AC9F-07F9-43C3-83E6-359A9CFBC80E} = {045965BC-9297-45DF-96E1-6986C286A81B} + {782DE093-CE87-48B5-A037-47C2189ACC13} = {6F154F8D-3437-45EE-9D89-02B96BDF3E8E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {FBA0CB49-EF2D-4538-9D00-FCEDA24879A9}