diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/BuilderWordDocumentOpenXML.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/BuilderWordDocumentOpenXML.cs index a998b36..4e500cc 100644 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/BuilderWordDocumentOpenXML.cs +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/BuilderWordDocumentOpenXML.cs @@ -2,7 +2,7 @@ using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using System.IO; -using ToolsOffice.Implements.WordOpenXML.Extenstions; +using ToolsOffice.Implements.WordOpenXML.Extensions; using ToolsOffice.Implements.WordOpenXML.Models; using ToolsOffice.Interfaces.Word; using ToolsOffice.Interfaces.Word.Models; @@ -17,57 +17,37 @@ namespace ToolsOffice.Implements.WordOpenXML private MemoryStream _memoryStream; - public override void CreateDocument(ICreateWordModel model) + public override void CreateDocument(ModelWordDocument model) { + var doc = WordCreateDocument.Create(model); + if (doc == null) + { + return; + } _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) + if (doc != null) { - mainPart.AddParts(document.WordDocumentParts); + mainPart.AddParts(doc.WordDocumentParts); } } - public override void CreateParagraph(IParagraphWordModel model) + public override void CreateParagraph(ModelWordParagraph 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); - } + _docBody.AddParagraph(model); } - public override void CreateTable(ITableWordModel model) + public override void CreateTable(ModelWordTable 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); - } + _docBody.AddTable(model); } - public override Stream SaveDocument(ISaveWordModel info) + public override Stream SaveDocument(ModelWordDocument info) { - if (info is WordSaveDocument document) - { - _docBody.AddSectionProperties(document); - } + _docBody.AddSectionProperties(info); _wordDocument.MainDocumentPart.Document.Save(); _wordDocument.Close(); return _memoryStream; diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordCellExtension.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordCellExtension.cs new file mode 100644 index 0000000..dae744f --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordCellExtension.cs @@ -0,0 +1,54 @@ +using DocumentFormat.OpenXml.Wordprocessing; +using ToolsOffice.Interfaces.Word.Models; + +namespace ToolsOffice.Implements.WordOpenXML.Extensions +{ + public static class WordCellExtension + { + /// + /// Добавление ячейки в строку + /// + /// + /// + public static void AddTableCell(this TableRow row, ModelWordTableCell model) + { + if (model == null) + { + return; + } + var cell = new TableCell(); + cell.AddTableCellProperties(model); + foreach (var paragraph in model.Texts) + { + cell.AddParagraph(paragraph); + } + row.AppendChild(cell); + } + + /// + /// Добавление свойств ячейки + /// + /// + /// + private static void AddTableCellProperties(this TableCell cell, ModelWordTableCell model) + { + if (model == null) + { + return; + } + var properties = new TableCellProperties(); + if (model.IsNewMerge) + { + properties.AppendChild(new VerticalMerge() + { + Val = MergedCellValues.Restart + }); + } + if (model.IsContinueMerge) + { + properties.AppendChild(new VerticalMerge()); + } + cell.AppendChild(properties); + } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordDocumentExtension.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordDocumentExtension.cs new file mode 100644 index 0000000..4830972 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordDocumentExtension.cs @@ -0,0 +1,169 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using System; +using ToolsModule.ManagmentExtension; +using ToolsOffice.Implements.WordOpenXML.Models; +using ToolsOffice.Interfaces.Word.Models; + +namespace ToolsOffice.Implements.WordOpenXML.Extensions +{ + public static class WordDocumentExtension + { + /// + /// Добавление общих элементов документа + /// + /// + /// + 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, ModelWordDocument model) + { + if (model == null) + { + return; + } + + var properties = new SectionProperties(); + + var pageSize = new PageSize(); + if (model.PageSizeHeight != null) + { + pageSize.Height = new UInt32Value(Convert.ToUInt32(model.PageSizeHeight.Value)); + } + if (model.PageSizeWidth != null) + { + pageSize.Width = new UInt32Value(Convert.ToUInt32(model.PageSizeWidth.Value)); + } + if (model.WordPageOrientation.HasValue) + { + pageSize.Orient = (PageOrientationValues)Enum.Parse(typeof(PageOrientationValues), model.WordPageOrientation.Value.ToString()); + } + properties.AppendChild(pageSize); + + var pageMargin = new PageMargin(); + if (model.PageMarginBottom.HasValue) + { + pageMargin.Bottom = model.PageMarginBottom.Value; + } + if (model.PageMarginFooter != null) + { + pageMargin.Footer = new UInt32Value(Convert.ToUInt32(model.PageMarginFooter.Value)); + } + if (model.PageMarginGutter != null) + { + pageMargin.Gutter = new UInt32Value(Convert.ToUInt32(model.PageMarginGutter.Value)); + } + if (model.PageMarginLeft != null) + { + pageMargin.Left = new UInt32Value(Convert.ToUInt32(model.PageMarginLeft.Value)); + } + if (model.PageMarginRight != null) + { + pageMargin.Right = new UInt32Value(Convert.ToUInt32(model.PageMarginRight.Value)); + } + if (model.PageMarginTop.HasValue) + { + pageMargin.Top = model.PageMarginTop.Value; + } + properties.AppendChild(pageMargin); + + body.AppendChild(properties); + } + + 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/Extensions/WordParagraphExtension.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordParagraphExtension.cs new file mode 100644 index 0000000..5a7e3d0 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordParagraphExtension.cs @@ -0,0 +1,134 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Wordprocessing; +using System; +using ToolsOffice.Interfaces.Word.Models; + +namespace ToolsOffice.Implements.WordOpenXML.Extensions +{ + public static class WordParagraphExtension + { + /// + /// Добавление абзаца в тело документа + /// + /// + /// + public static void AddParagraph(this Body body, ModelWordParagraph model) + { + if (model == null) + { + return; + } + var paragraph = new Paragraph(); + paragraph.AddParagraphProperties(model); + if (model.WordTexts != null) + { + foreach (var text in model.WordTexts) + { + paragraph.AddRun(text); + } + } + body.AppendChild(paragraph); + } + + /// + /// Добавление абзаца в ячейку таблицы + /// + /// + /// + public static void AddParagraph(this TableCell cell, ModelWordParagraph model) + { + if (model == null) + { + return; + } + var paragraph = new Paragraph(); + paragraph.AddParagraphProperties(model); + if (model.WordTexts != null) + { + foreach (var text in model.WordTexts) + { + paragraph.AddRun(text); + } + } + cell.AppendChild(paragraph); + } + + /// + /// Добавление свойств абзаца + /// + /// + /// + private static void AddParagraphProperties(this Paragraph paragraph, ModelWordParagraph model) + { + if (model == null) + { + return; + } + var properties = new ParagraphProperties(); + + if (model.JustificationType.HasValue) + { + var justification = new Justification() + { + Val = (JustificationValues)Enum.Parse(typeof(JustificationValues), model.JustificationType.Value.ToString()) + }; + properties.AppendChild(justification); + } + + var spacingBetweenLines = new SpacingBetweenLines(); + if (model.SpacingBetweenLinesLine != null) + { + spacingBetweenLines.Line = new StringValue(model.SpacingBetweenLinesLine.Value.ToString()); + } + if (model.SpacingBetweenLinesBefore != null) + { + spacingBetweenLines.Before = new StringValue(model.SpacingBetweenLinesBefore.Value.ToString()); + } + if (model.SpacingBetweenLinesAfter != null) + { + spacingBetweenLines.After = new StringValue(model.SpacingBetweenLinesAfter.Value.ToString()); + } + properties.AppendChild(spacingBetweenLines); + + var indentation = new Indentation(); + if (model.IndentationFirstLine != null) + { + indentation.FirstLine = new StringValue(model.IndentationFirstLine.Value.ToString()); + } + if (model.IndentationHanging != null) + { + indentation.Hanging = new StringValue(model.IndentationHanging.Value.ToString()); + } + if (model.IndentationLeft != null) + { + indentation.Left = new StringValue(model.IndentationLeft.Value.ToString()); + } + if (model.IndentationRight != null) + { + indentation.Right = new StringValue(model.IndentationRight.Value.ToString()); + } + properties.AppendChild(indentation); + + var paragraphMarkRunProperties = new ParagraphMarkRunProperties(); + if (model.FontSize.HasValue) + { + paragraphMarkRunProperties.AppendChild(new FontSize { Val = new StringValue(model.FontSize.Value.ToString()) }); + } + if (model.IsBold) + { + paragraphMarkRunProperties.AppendChild(new Bold()); + } + if (model.IsItalic) + { + paragraphMarkRunProperties.AppendChild(new Italic()); + } + if (model.IsUnderline) + { + paragraphMarkRunProperties.AppendChild(new Underline()); + } + properties.AppendChild(paragraphMarkRunProperties); + + paragraph.AppendChild(properties); + } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordRowExtension.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordRowExtension.cs new file mode 100644 index 0000000..989e531 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordRowExtension.cs @@ -0,0 +1,49 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Wordprocessing; +using System; +using ToolsOffice.Interfaces.Word.Models; + +namespace ToolsOffice.Implements.WordOpenXML.Extensions +{ + public static class WordRowExtension + { + /// + /// Добавление строки в таблицу + /// + /// + /// + public static void AddTableRow(this Table table, ModelWordTableRow model) + { + if (model == null) + { + return; + } + var row = new TableRow(); + row.AddTableRowProperties(model); + foreach (var cell in model.Cells) + { + row.AddTableCell(cell); + } + table.AppendChild(row); + } + + /// + /// Добавление свойств строки + /// + /// + /// + private static void AddTableRowProperties(this TableRow row, ModelWordTableRow model) + { + if (model == null) + { + return; + } + if (model.Height.HasValue) + { + var properties = new TableRowProperties(); + properties.AppendChild(new TableRowHeight() { Val = new UInt32Value(Convert.ToUInt32(model.Height.Value)) }); + row.AppendChild(properties); + } + } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordRunExtension.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordRunExtension.cs new file mode 100644 index 0000000..3935661 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordRunExtension.cs @@ -0,0 +1,72 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Wordprocessing; +using ToolsOffice.Interfaces.Word.Models; + +namespace ToolsOffice.Implements.WordOpenXML.Extensions +{ + public static class WordRunExtension + { + /// + /// Добавление текста в абзац + /// + /// + /// + public static void AddRun(this Paragraph paragraph, ModelWordText model) + { + if (model == null) + { + return; + } + var docRun = new Run(); + docRun.AddRunProperties(model); + if (model.IsBreak) + { + docRun.AppendChild(new Break()); + } + else if (model.IsTabChar) + { + docRun.AppendChild(new TabChar()); + } + else + { + docRun.AppendChild(new Text { Text = model.Text, Space = SpaceProcessingModeValues.Preserve }); + } + paragraph.AppendChild(docRun); + } + + /// + /// Добавление свойств текста + /// + /// + /// + private static void AddRunProperties(this Run run, ModelWordText model) + { + if (model == null) + { + return; + } + + if (model.FontSize.HasValue || model.IsBold || model.IsItalic || model.IsUnderline) + { + var properties = new RunProperties(); + if (model.FontSize.HasValue) + { + properties.AppendChild(new FontSize { Val = new StringValue(model.FontSize.Value.ToString()) }); + } + if (model.IsBold) + { + properties.AppendChild(new Bold()); + } + if (model.IsItalic) + { + properties.AppendChild(new Italic()); + } + if (model.IsUnderline) + { + properties.AppendChild(new Underline()); + } + run.AppendChild(properties); + } + } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordTableExtension.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordTableExtension.cs new file mode 100644 index 0000000..4df55a4 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordTableExtension.cs @@ -0,0 +1,251 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Wordprocessing; +using System; +using System.Collections.Generic; +using System.Linq; +using ToolsOffice.Interfaces.Word.Models; + +namespace ToolsOffice.Implements.WordOpenXML.Extensions +{ + public static class WordTableExtension + { + /// + /// Добавление таблицы в тело документа + /// + /// + /// + public static void AddTable(this Body body, ModelWordTable model) + { + if (model == null) + { + return; + } + model.CreateRows(); + var table = new Table(); + table.AddTableProperties(model); + table.AddGridColumn(model); + foreach (var row in model.Rows) + { + table.AddTableRow(row); + } + body.AppendChild(table); + } + + /// + /// Создание строк таблицы на основе входных данных + /// + /// + private static void CreateRows(this ModelWordTable model) + { + model.Rows = new Queue(); + + var headerRowsCount = model.Headers.Select(x => x.RowIndex).Distinct().Count(); + + for(int rowIndex = 0; rowIndex < headerRowsCount; ++rowIndex) + { + var header = new ModelWordTableRow(); + if (model.RowsHeight.ContainsKey(rowIndex)) + { + header.Height = model.RowsHeight[rowIndex]; + } + for (int i = 0; i < model.Data.GetLength(1); ++i) + { + header.Cells.Enqueue(CreateHeaderCell(model, rowIndex, i)); + } + model.Rows.Enqueue(header); + } + for (int i = 0; i < model.Data.Length; ++i) + { + var row = new ModelWordTableRow(); + if (model.RowsHeight.ContainsKey(i + headerRowsCount)) + { + row.Height = model.RowsHeight[i + headerRowsCount]; + } + for (int j = 0; j < model.Data.GetLength(1); ++j) + { + row.Cells.Enqueue(CreateCell(model, i, j)); + } + model.Rows.Enqueue(row); + } + } + + /// + /// Добавление свойсвт таблицы + /// + /// + /// + private static void AddTableProperties(this Table table, ModelWordTable model) + { + if (model == null) + { + return; + } + + var properties = new TableProperties(); + + var tableLook = new TableLook(); + if (model.LookFirstRow) + { + tableLook.FirstRow = new OnOffValue(model.LookFirstRow); + } + if (model.LookFirstColumn) + { + tableLook.FirstColumn = new OnOffValue(model.LookFirstColumn); + } + if (model.LookLastRow) + { + tableLook.LastRow = new OnOffValue(model.LookLastRow); + } + if (model.LookLastColumn) + { + tableLook.LastColumn = new OnOffValue(model.LookLastColumn); + } + if (model.LookNoHorizontalBand) + { + tableLook.NoHorizontalBand = new OnOffValue(model.LookNoHorizontalBand); + } + if (model.LookNoVerticalBand) + { + tableLook.NoVerticalBand = new OnOffValue(model.LookNoVerticalBand); + } + properties.AppendChild(tableLook); + + var tableBorders = new TableBorders(); + tableBorders.AddBorder(model, new TopBorder()); + tableBorders.AddBorder(model, new BottomBorder()); + tableBorders.AddBorder(model, new LeftBorder()); + tableBorders.AddBorder(model, new RightBorder()); + + properties.AppendChild(tableBorders); + + table.AppendChild(properties); + } + + /// + /// Добавление колонок таблицы + /// + /// + /// + private static void AddGridColumn(this Table table, ModelWordTable model) + { + if (model == null || model.ColumnWidths == null || model.ColumnWidths.Count == 0) + { + return; + } + var tableGrid = new TableGrid(); + foreach (var grid in model.ColumnWidths) + { + tableGrid.AppendChild(new GridColumn() { Width = new StringValue(grid.ToString()) }); + } + table.AppendChild(tableGrid); + } + + /// + /// Добавление границ таблицы + /// + /// + /// + /// + private static void AddBorder(this TableBorders tableBorders, ModelWordTable model, BorderType borderType) + { + if (model == null) + { + return; + } + if (model.BorderType.HasValue) + { + borderType.Val = (BorderValues)Enum.Parse(typeof(BorderValues), model.BorderType.Value.ToString()); + } + tableBorders.AppendChild(borderType); + } + + /// + /// Создание ячейки строки-заголовка + /// + /// + /// + /// + /// + private static ModelWordTableCell CreateHeaderCell(ModelWordTable model, int rowIndex, int columnIndex) + { + var cell = new ModelWordTableCell(); + var elem = model.Headers.FirstOrDefault(x => x.ColumnIndex == columnIndex && x.RowIndex == rowIndex); + if (elem != default) + { + cell.Texts = new Queue(); + var paragraph = new ModelWordParagraph + { + FontSize = 14, + FontName = Interfaces.FontNames.TimesNewRoman, + IsBold = true, + JustificationType = TypeWordJustification.Center, + WordTexts = new Queue() + }; + paragraph.WordTexts.Enqueue(new ModelWordText + { + Text = elem.Header + }); + cell.Texts.Enqueue(paragraph); + } + else + { + var union = model.CellUnion.FirstOrDefault(x => x.StartColumnIndex >= columnIndex && x.StartRowIndex >= rowIndex && + x.FinishColumnIndex <= columnIndex && x.FinishRowIndex <= rowIndex); + if (union != default) + { + if (union.StartColumnIndex == columnIndex) + { + cell.IsNewMerge = true; + } + else + { + cell.IsContinueMerge = true; + } + } + } + return cell; + } + + /// + /// Создание ячейки строки данных + /// + /// + /// + /// + /// + private static ModelWordTableCell CreateCell(ModelWordTable model, int rowIndex, int columnIndex) + { + var cell = new ModelWordTableCell(); + var union = model.CellUnion.FirstOrDefault(x => x.StartColumnIndex >= columnIndex && x.StartRowIndex >= rowIndex && + x.FinishColumnIndex <= columnIndex && x.FinishRowIndex <= rowIndex); + if (union != default) + { + if (union.StartColumnIndex == columnIndex) + { + cell.IsNewMerge = true; + } + else + { + cell.IsContinueMerge = true; + } + } + else + { + cell.Texts = new Queue(); + var paragraph = new ModelWordParagraph + { + FontSize = 14, + FontName = Interfaces.FontNames.TimesNewRoman, + JustificationType = TypeWordJustification.Left, + WordTexts = new Queue() + }; + paragraph.WordTexts.Enqueue(new ModelWordText + { + Text = model.Data[rowIndex, columnIndex] + }); + cell.Texts.Enqueue(paragraph); + } + return cell; + } + } +} \ 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 deleted file mode 100644 index c31f2f8..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extenstions/WordDocumentExtenstion.cs +++ /dev/null @@ -1,516 +0,0 @@ -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 index 76def18..a2a5df9 100644 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordCreateDocument.cs +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordCreateDocument.cs @@ -2,8 +2,17 @@ namespace ToolsOffice.Implements.WordOpenXML.Models { - public class WordCreateDocument : ICreateWordModel + public class WordCreateDocument { public WordDocumentParts WordDocumentParts { get; set; } + + public static WordCreateDocument Create(ModelWordDocument model) + { + if (model == null) + { + return null; + } + return new WordCreateDocument(); + } } } \ 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 deleted file mode 100644 index 371bb13..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordDocumentSettings.cs +++ /dev/null @@ -1,26 +0,0 @@ -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 deleted file mode 100644 index 04fb33b..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordJustificationType.cs +++ /dev/null @@ -1,13 +0,0 @@ -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/WordParagraph.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordParagraph.cs deleted file mode 100644 index 37fafb2..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordParagraph.cs +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 5b2a639..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordParagraphProperties.cs +++ /dev/null @@ -1,31 +0,0 @@ -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 deleted file mode 100644 index 19fc568..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordRun.cs +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index e97bad2..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordRunProperties.cs +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 130aa39..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordSaveDocument.cs +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index c59f691..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTable.cs +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 2f6b40d..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableBorder.cs +++ /dev/null @@ -1,15 +0,0 @@ -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/WordTableCell.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableCell.cs deleted file mode 100644 index c19a171..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableCell.cs +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 392192c..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableCellProperties.cs +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index ac4a5ed..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableGrid.cs +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index fd5ee89..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableProperties.cs +++ /dev/null @@ -1,31 +0,0 @@ -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 deleted file mode 100644 index a21687c..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableRow.cs +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 9220936..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableRowProperties.cs +++ /dev/null @@ -1,11 +0,0 @@ -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/FontNames.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/FontNames.cs new file mode 100644 index 0000000..0b3f6c2 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/FontNames.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ToolsOffice.Interfaces +{ + public enum FontNames + { + TimesNewRoman = 0 + } +} diff --git a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/BuilderWordDocument.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/BuilderWordDocument.cs index 661836d..0122b9f 100644 --- a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/BuilderWordDocument.cs +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/BuilderWordDocument.cs @@ -9,24 +9,24 @@ namespace ToolsOffice.Interfaces.Word /// Создание документа /// /// - public abstract void CreateDocument(ICreateWordModel model); + public abstract void CreateDocument(ModelWordDocument model); /// /// Создание абзаца с текстом /// /// - public abstract void CreateParagraph(IParagraphWordModel model); + public abstract void CreateParagraph(ModelWordParagraph model); /// /// Создание абзаца с текстом /// /// - public abstract void CreateTable(ITableWordModel model); + public abstract void CreateTable(ModelWordTable model); /// /// Сохранение файла /// /// - public abstract Stream SaveDocument(ISaveWordModel info); + public abstract Stream SaveDocument(ModelWordDocument 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 deleted file mode 100644 index 009121e..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ICreateWordModel.cs +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index 1bdf6b3..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/IParagraphWordModel.cs +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index 856273a..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ISaveWordModel.cs +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index 297c22c..0000000 --- a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ITableWordModel.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace ToolsOffice.Interfaces.Word.Models -{ - public interface ITableWordModel { } -} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/IWordDocumentPartModel.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/IWordDocumentPartModel.cs new file mode 100644 index 0000000..64d17c9 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/IWordDocumentPartModel.cs @@ -0,0 +1,7 @@ +namespace ToolsOffice.Interfaces.Word.Models +{ + /// + /// Модель данных при создании элемента документа (абзац, таблица) + /// + public interface IWordDocumentPartModel { } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ModelWordDocument.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ModelWordDocument.cs new file mode 100644 index 0000000..d49c8f6 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ModelWordDocument.cs @@ -0,0 +1,36 @@ +namespace ToolsOffice.Interfaces.Word.Models +{ + /// + /// Модель описания документа + /// + public class ModelWordDocument + { + /// + /// Высота страницы + /// + public int? PageSizeHeight { get; set; } + + /// + /// Ширина страницы + /// + public int? PageSizeWidth { get; set; } + + /// + /// Ориентация страницы + /// + public TypeWordPageOrientation? WordPageOrientation { get; set; } + + + public int? PageMarginFooter { get; set; } + + public int? PageMarginGutter { get; set; } + + public int? PageMarginBottom { get; set; } + + public int? PageMarginTop { get; set; } + + public int? PageMarginLeft { get; set; } + + public int? PageMarginRight { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ModelWordParagraph.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ModelWordParagraph.cs new file mode 100644 index 0000000..5267ea9 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ModelWordParagraph.cs @@ -0,0 +1,80 @@ +using System.Collections.Generic; + +namespace ToolsOffice.Interfaces.Word.Models +{ + /// + /// Модель описания абзаца документа + /// + public class ModelWordParagraph : IWordDocumentPartModel + { + /// + /// Набор текстов + /// + public Queue WordTexts { get; set; } + + /// + /// Размер шрифта + /// + public int? FontSize { get; set; } + + /// + /// Название шрифта + /// + public FontNames FontName { get; set; } + + /// + /// Жирный + /// + public bool IsBold { get; set; } = false; + + /// + /// Курсив + /// + public bool IsItalic { get; set; } = false; + + /// + /// Подчеркивание + /// + public bool IsUnderline { get; set; } = false; + + /// + /// Выравнивание абзаца + /// + public TypeWordJustification? JustificationType { get; set; } + + /// + /// Расстояние между строками абзаца + /// + public int? SpacingBetweenLinesLine { get; set; } + + /// + /// Отступ до абзаца + /// + public int? SpacingBetweenLinesBefore { get; set; } + + /// + /// Отступ после абзаца + /// + public int? SpacingBetweenLinesAfter { get; set; } + + /// + /// Отступ первой строки + /// + public int? IndentationFirstLine { get; set; } + + /// + /// Выступ + /// + public int? IndentationHanging { get; set; } + + /// + /// Отступ слева + /// + public int? IndentationLeft { get; set; } + + /// + /// Отступ справа + /// + public int? IndentationRight { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ModelWordTable.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ModelWordTable.cs new file mode 100644 index 0000000..5d3ab52 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ModelWordTable.cs @@ -0,0 +1,75 @@ +using System.Collections.Generic; + +namespace ToolsOffice.Interfaces.Word.Models +{ + /// + /// Модель описания таблицы документа + /// + public class ModelWordTable : IWordDocumentPartModel + { + /// + /// Информация по ширине колонок (номер колонки, ширина колонки), отсчет с 0 + /// + public Dictionary ColumnWidths { get; set; } + + /// + /// Информация по высоте строк (номер строки, высота строки), отсчет с 0 + /// + public Dictionary RowsHeight { get; set; } + + /// + /// Информация по объединению ячеек + /// + public List<(int StartRowIndex, int StartColumnIndex, int FinishRowIndex, int FinishColumnIndex)> CellUnion { get; set; } + + /// + /// Заголовки для таблицы + /// + public List<(int ColumnIndex, int RowIndex, string Header)> Headers { get; set; } + + /// + /// Данные + /// + public string[,] Data { 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 TypeWordTableBorder? BorderType { get; set; } + + /// + /// Список строк для таблицы + /// + public Queue Rows { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ModelWordTableCell.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ModelWordTableCell.cs new file mode 100644 index 0000000..55e3213 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ModelWordTableCell.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; + +namespace ToolsOffice.Interfaces.Word.Models +{ + /// + /// Модель описания ячейки таблицы + /// + public class ModelWordTableCell + { + /// + /// Новое объединение ячеек + /// + public bool IsNewMerge {get;set; } + + /// + /// Признак, продолжения объединения ячеек + /// + public bool IsContinueMerge { get; set; } + + /// + /// Абзацы текста в ячейке + /// + public Queue Texts { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ModelWordTableRow.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ModelWordTableRow.cs new file mode 100644 index 0000000..1930474 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ModelWordTableRow.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +namespace ToolsOffice.Interfaces.Word.Models +{ + /// + /// Модель описания строки таблицы + /// + public class ModelWordTableRow + { + /// + /// Высота строки + /// + public int? Height { get; set; } + + /// + /// Список ячеек строки + /// + public Queue Cells { get; set; } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ModelWordText.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ModelWordText.cs new file mode 100644 index 0000000..edf1df4 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/ModelWordText.cs @@ -0,0 +1,43 @@ +namespace ToolsOffice.Interfaces.Word.Models +{ + /// + /// Модель описания текста из абзаца документа + /// + public class ModelWordText + { + /// + /// Сам текст + /// + public string Text { get; set; } + + /// + /// Признак разрыва страниц + /// + public bool IsBreak { get; set; } = false; + + /// + /// Признак табулятора + /// + public bool IsTabChar { get; set; } = false; + + /// + /// Размер шрифта + /// + public int? FontSize { get; set; } + + /// + /// Жирный + /// + public bool IsBold { get; set; } = false; + + /// + /// Курсив + /// + public bool IsItalic { get; set; } = false; + + /// + /// Подчеркивание + /// + public bool IsUnderline { get; set; } = false; + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/TypeWordJustification.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/TypeWordJustification.cs new file mode 100644 index 0000000..212ae63 --- /dev/null +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/TypeWordJustification.cs @@ -0,0 +1,16 @@ +namespace ToolsOffice.Interfaces.Word.Models +{ + /// + /// Выравнивание абзаца + /// + public enum TypeWordJustification + { + 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/Interfaces/Word/Models/TypeWordPageOrientation.cs similarity index 62% rename from DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordPageOrientationType.cs rename to DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/TypeWordPageOrientation.cs index b91c497..e0eab7f 100644 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordPageOrientationType.cs +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/TypeWordPageOrientation.cs @@ -1,9 +1,9 @@ -namespace ToolsOffice.Implements.WordOpenXML.Models +namespace ToolsOffice.Interfaces.Word.Models { /// /// Ориентация страниц документа /// - public enum WordPageOrientationType + public enum TypeWordPageOrientation { Portrait = 0, diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableBorderType.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/TypeWordTableBorder.cs similarity index 52% rename from DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableBorderType.cs rename to DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/TypeWordTableBorder.cs index 5c21b88..90dff67 100644 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Models/WordTableBorderType.cs +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/TypeWordTableBorder.cs @@ -1,6 +1,9 @@ -namespace ToolsOffice.Implements.WordOpenXML.Models +namespace ToolsOffice.Interfaces.Word.Models { - public enum WordTableBorderType + /// + /// Тип границ таблицы + /// + public enum TypeWordTableBorder { None = 1,