мелкие правки по пакету

This commit is contained in:
kotcheshir73 2022-12-20 13:36:46 +04:00
parent b59e0e09c2
commit 92f9e9f8e9
7 changed files with 39 additions and 33 deletions

View File

@ -1,6 +1,7 @@
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Wordprocessing;
using System;
using ToolsOffice.Interfaces;
using ToolsOffice.Interfaces.Word.Models;
namespace ToolsOffice.Implements.WordOpenXML.Extensions
@ -8,6 +9,7 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
public static class WordDocumentExtension
{
private static readonly int _coefToPoins = 567;
/// <summary>
/// Добавление общих настроек документа
/// </summary>
@ -70,5 +72,16 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
body.AppendChild(properties);
}
/// <summary>
/// Получение шрифта из FontNames
/// </summary>
/// <param name="fn"></param>
/// <returns></returns>
public static (string Ascii, string HighAnsi, string ComplexScript) GetFontName(FontNames fn) => fn switch
{
FontNames.TimesNewRoman => ("Times New Roman", "Times New Roman", "Times New Roman"),
_ => default,
};
}
}

View File

@ -2,7 +2,6 @@
using DocumentFormat.OpenXml.Wordprocessing;
using System;
using ToolsModule.ManagmentExtension;
using ToolsOffice.Interfaces;
using ToolsOffice.Interfaces.Word.Models;
namespace ToolsOffice.Implements.WordOpenXML.Extensions
@ -96,7 +95,7 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
if (model.FontName.HasValue)
{
var font = GetFontName(model.FontName.Value);
var font = WordDocumentExtension.GetFontName(model.FontName.Value);
paragraphMarkRunProperties.AppendChild(new RunFonts
{
Ascii = new StringValue(font.Ascii),
@ -138,37 +137,26 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
if (model.Text.IsNotEmpty())
{
var text = new ModelWordText { Text = model.Text };
CheckRunProps(model, text);
SyncRunProps(model, text);
paragraph.AddRun(text);
}
else if (model.WordTexts != null)
{
foreach (var text in model.WordTexts)
{
CheckRunProps(model, text);
SyncRunProps(model, text);
paragraph.AddRun(text);
}
}
return paragraph;
}
/// <summary>
/// Получение шрифта из FontNames
/// </summary>
/// <param name="fn"></param>
/// <returns></returns>
private static (string Ascii, string HighAnsi, string ComplexScript) GetFontName(FontNames fn) => fn switch
{
FontNames.TimesNewRoman => ("Times New Roman", "Times New Roman", "Times New Roman"),
_ => default,
};
/// <summary>
/// Пеоедача параметров текста из параметров абзаца, если не заданы параметры текста
/// </summary>
/// <param name="paragraph"></param>
/// <param name="run"></param>
private static void CheckRunProps(ModelWordParagraph paragraph, ModelWordText run)
private static void SyncRunProps(ModelWordParagraph paragraph, ModelWordText run)
{
if (run == null)
{

View File

@ -1,6 +1,5 @@
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Wordprocessing;
using ToolsOffice.Interfaces;
using ToolsOffice.Interfaces.Word.Models;
namespace ToolsOffice.Implements.WordOpenXML.Extensions
@ -52,7 +51,7 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
var properties = new RunProperties();
if (model.FontName.HasValue)
{
var font = GetFontName(model.FontName.Value);
var font = WordDocumentExtension.GetFontName(model.FontName.Value);
properties.AppendChild(new RunFonts
{
Ascii = new StringValue(font.Ascii),
@ -80,16 +79,5 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
run.AppendChild(properties);
}
}
/// <summary>
/// Получение шрифта из FontNames
/// </summary>
/// <param name="fn"></param>
/// <returns></returns>
private static (string Ascii, string HighAnsi, string ComplexScript) GetFontName(FontNames fn) => fn switch
{
FontNames.TimesNewRoman => ("Times New Roman", "Times New Roman", "Times New Roman"),
_ => default,
};
}
}

View File

@ -6,6 +6,11 @@ namespace ToolsOffice.Interfaces.Word
{
public abstract class BuilderWordDocument
{
/// <summary>
/// Создание документа с заголовком и таблицей
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public Stream CreateDocumentWithTable(ModelWordDocumentWithHeaderAndTable model)
{
if (model == null || model.Document == null || model.Header == null || model.Table == null)

View File

@ -1,14 +1,23 @@
namespace ToolsOffice.Interfaces.Word.Models.Cases
{
/// <summary>
/// Модель для создания простого документа с шапкой и таблицей
/// Модель для создания простого документа с заголовком и таблицей
/// </summary>
public class ModelWordDocumentWithHeaderAndTable
{
/// <summary>
/// Информация по документу
/// </summary>
public ModelWordDocument Document { get; set; }
/// <summary>
/// Заголовок
/// </summary>
public ModelWordParagraph Header { get; set; }
/// <summary>
/// Таблица
/// </summary>
public ModelWordTable Table { get; set; }
}
}

View File

@ -3,7 +3,10 @@ using System.Linq;
namespace ToolsOffice.Interfaces.Word
{
public class PageSizes
/// <summary>
/// Размеры страниц документов (портретная ориентация)
/// </summary>
public class WordPageSizes
{
private static readonly
Dictionary<string, (double Height, double Width, double MarginBottom, double MarginTop, double MarginLeft, double MarginRigth, double MarginGutter, double Header, double Footer)> _sizes = new()
@ -17,7 +20,7 @@ namespace ToolsOffice.Interfaces.Word
private readonly string _key;
public PageSizes(string key)
public WordPageSizes(string key)
{
_hasKey = _sizes.ContainsKey(key);
_key = key;

View File

@ -149,7 +149,7 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic
rowIndex++;
}
var pageSize = new PageSizes("А4");
var pageSize = new WordPageSizes("А4");
var docModel = new ModelWordDocumentWithHeaderAndTable
{
Document = new ModelWordDocument