Правки по пакету word
This commit is contained in:
parent
faa59fbd6e
commit
72cb1f1e63
@ -1,10 +1,13 @@
|
|||||||
using DocumentFormat.OpenXml.Wordprocessing;
|
using DocumentFormat.OpenXml;
|
||||||
|
using DocumentFormat.OpenXml.Wordprocessing;
|
||||||
using ToolsOffice.Interfaces.Word.Models;
|
using ToolsOffice.Interfaces.Word.Models;
|
||||||
|
|
||||||
namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
||||||
{
|
{
|
||||||
public static class WordCellExtension
|
public static class WordCellExtension
|
||||||
{
|
{
|
||||||
|
private static readonly int _coefToPoins = 567;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление ячейки в строку
|
/// Добавление ячейки в строку
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -37,6 +40,10 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var properties = new TableCellProperties();
|
var properties = new TableCellProperties();
|
||||||
|
if (model.Width.HasValue)
|
||||||
|
{
|
||||||
|
properties.AppendChild(new TableCellWidth { Width = new StringValue((model.Width.Value * _coefToPoins).ToString()), Type = TableWidthUnitValues.Dxa });
|
||||||
|
}
|
||||||
if (model.IsNewMerge)
|
if (model.IsNewMerge)
|
||||||
{
|
{
|
||||||
properties.AppendChild(new VerticalMerge()
|
properties.AppendChild(new VerticalMerge()
|
||||||
|
@ -7,6 +7,7 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
{
|
{
|
||||||
public static class WordDocumentExtension
|
public static class WordDocumentExtension
|
||||||
{
|
{
|
||||||
|
private static readonly int _coefToPoins = 567;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление общих настроек документа
|
/// Добавление общих настроек документа
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -24,11 +25,11 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
var pageSize = new PageSize();
|
var pageSize = new PageSize();
|
||||||
if (model.PageSizeHeight != null)
|
if (model.PageSizeHeight != null)
|
||||||
{
|
{
|
||||||
pageSize.Height = new UInt32Value(Convert.ToUInt32(model.PageSizeHeight.Value));
|
pageSize.Height = new UInt32Value(Convert.ToUInt32(model.PageSizeHeight.Value * _coefToPoins));
|
||||||
}
|
}
|
||||||
if (model.PageSizeWidth != null)
|
if (model.PageSizeWidth != null)
|
||||||
{
|
{
|
||||||
pageSize.Width = new UInt32Value(Convert.ToUInt32(model.PageSizeWidth.Value));
|
pageSize.Width = new UInt32Value(Convert.ToUInt32(model.PageSizeWidth.Value * _coefToPoins));
|
||||||
}
|
}
|
||||||
if (model.WordPageOrientation.HasValue)
|
if (model.WordPageOrientation.HasValue)
|
||||||
{
|
{
|
||||||
@ -39,19 +40,31 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
var pageMargin = new PageMargin();
|
var pageMargin = new PageMargin();
|
||||||
if (model.PageMarginBottom.HasValue)
|
if (model.PageMarginBottom.HasValue)
|
||||||
{
|
{
|
||||||
pageMargin.Bottom = Convert.ToInt32(model.PageMarginBottom.Value);
|
pageMargin.Bottom = Convert.ToInt32(model.PageMarginBottom.Value * _coefToPoins);
|
||||||
}
|
}
|
||||||
if (model.PageMarginLeft != null)
|
if (model.PageMarginLeft != null)
|
||||||
{
|
{
|
||||||
pageMargin.Left = new UInt32Value(Convert.ToUInt32(model.PageMarginLeft.Value));
|
pageMargin.Left = new UInt32Value(Convert.ToUInt32(model.PageMarginLeft.Value * _coefToPoins));
|
||||||
}
|
}
|
||||||
if (model.PageMarginRight != null)
|
if (model.PageMarginRight != null)
|
||||||
{
|
{
|
||||||
pageMargin.Right = new UInt32Value(Convert.ToUInt32(model.PageMarginRight.Value));
|
pageMargin.Right = new UInt32Value(Convert.ToUInt32(model.PageMarginRight.Value * _coefToPoins));
|
||||||
}
|
}
|
||||||
if (model.PageMarginTop.HasValue)
|
if (model.PageMarginTop.HasValue)
|
||||||
{
|
{
|
||||||
pageMargin.Top = Convert.ToInt32(model.PageMarginTop.Value);
|
pageMargin.Top = Convert.ToInt32(model.PageMarginTop.Value * _coefToPoins);
|
||||||
|
}
|
||||||
|
if (model.PageMarginGutter.HasValue)
|
||||||
|
{
|
||||||
|
pageMargin.Gutter = new UInt32Value(Convert.ToUInt32(model.PageMarginGutter.Value * _coefToPoins));
|
||||||
|
}
|
||||||
|
if (model.PageHeader.HasValue)
|
||||||
|
{
|
||||||
|
pageMargin.Header = new UInt32Value(Convert.ToUInt32(model.PageHeader.Value * _coefToPoins));
|
||||||
|
}
|
||||||
|
if (model.PageFooter.HasValue)
|
||||||
|
{
|
||||||
|
pageMargin.Footer = new UInt32Value(Convert.ToUInt32(model.PageFooter.Value * _coefToPoins));
|
||||||
}
|
}
|
||||||
properties.AppendChild(pageMargin);
|
properties.AppendChild(pageMargin);
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using DocumentFormat.OpenXml.Wordprocessing;
|
using DocumentFormat.OpenXml.Wordprocessing;
|
||||||
using System;
|
using System;
|
||||||
using ToolsModule.ManagmentExtension;
|
using ToolsModule.ManagmentExtension;
|
||||||
|
using ToolsOffice.Interfaces;
|
||||||
using ToolsOffice.Interfaces.Word.Models;
|
using ToolsOffice.Interfaces.Word.Models;
|
||||||
|
|
||||||
namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
||||||
@ -19,20 +20,7 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var paragraph = new Paragraph();
|
body.AppendChild(CreateParagraph(model));
|
||||||
paragraph.AddParagraphProperties(model);
|
|
||||||
if (model.Text.IsNotEmpty())
|
|
||||||
{
|
|
||||||
paragraph.AddRun(model.Text);
|
|
||||||
}
|
|
||||||
else if (model.WordTexts != null)
|
|
||||||
{
|
|
||||||
foreach (var text in model.WordTexts)
|
|
||||||
{
|
|
||||||
paragraph.AddRun(text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
body.AppendChild(paragraph);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -46,20 +34,7 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var paragraph = new Paragraph();
|
cell.AppendChild(CreateParagraph(model));
|
||||||
paragraph.AddParagraphProperties(model);
|
|
||||||
if (model.Text.IsNotEmpty())
|
|
||||||
{
|
|
||||||
paragraph.AddRun(model.Text);
|
|
||||||
}
|
|
||||||
else if (model.WordTexts != null)
|
|
||||||
{
|
|
||||||
foreach (var text in model.WordTexts)
|
|
||||||
{
|
|
||||||
paragraph.AddRun(text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cell.AppendChild(paragraph);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -119,9 +94,20 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
properties.AppendChild(indentation);
|
properties.AppendChild(indentation);
|
||||||
|
|
||||||
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
|
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
|
||||||
|
if (model.FontName.HasValue)
|
||||||
|
{
|
||||||
|
var font = GetFontName(model.FontName.Value);
|
||||||
|
paragraphMarkRunProperties.AppendChild(new RunFonts
|
||||||
|
{
|
||||||
|
Ascii = new StringValue(font.Ascii),
|
||||||
|
HighAnsi = new StringValue(font.HighAnsi),
|
||||||
|
ComplexScript = new StringValue(font.ComplexScript)
|
||||||
|
});
|
||||||
|
}
|
||||||
if (model.FontSize.HasValue)
|
if (model.FontSize.HasValue)
|
||||||
{
|
{
|
||||||
paragraphMarkRunProperties.AppendChild(new FontSize { Val = new StringValue(model.FontSize.Value.ToString()) });
|
paragraphMarkRunProperties.AppendChild(new FontSize { Val = new StringValue((model.FontSize.Value * 1.75).ToString()) });
|
||||||
|
paragraphMarkRunProperties.AppendChild(new FontSizeComplexScript { Val = new StringValue((model.FontSize.Value * 1.75).ToString()) });
|
||||||
}
|
}
|
||||||
if (model.IsBold)
|
if (model.IsBold)
|
||||||
{
|
{
|
||||||
@ -139,5 +125,76 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
|
|
||||||
paragraph.AppendChild(properties);
|
paragraph.AppendChild(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создание абзаца
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static Paragraph CreateParagraph(ModelWordParagraph model)
|
||||||
|
{
|
||||||
|
var paragraph = new Paragraph();
|
||||||
|
paragraph.AddParagraphProperties(model);
|
||||||
|
if (model.Text.IsNotEmpty())
|
||||||
|
{
|
||||||
|
var text = new ModelWordText { Text = model.Text };
|
||||||
|
CheckRunProps(model, text);
|
||||||
|
paragraph.AddRun(text);
|
||||||
|
}
|
||||||
|
else if (model.WordTexts != null)
|
||||||
|
{
|
||||||
|
foreach (var text in model.WordTexts)
|
||||||
|
{
|
||||||
|
CheckRunProps(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)
|
||||||
|
{
|
||||||
|
if (run == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!run.FontSize.HasValue)
|
||||||
|
{
|
||||||
|
run.FontSize = paragraph.FontSize;
|
||||||
|
}
|
||||||
|
if (!run.FontName.HasValue)
|
||||||
|
{
|
||||||
|
run.FontName = paragraph.FontName;
|
||||||
|
}
|
||||||
|
if (!run.IsBold.HasValue)
|
||||||
|
{
|
||||||
|
run.IsBold = paragraph.IsBold;
|
||||||
|
}
|
||||||
|
if (!run.IsItalic.HasValue)
|
||||||
|
{
|
||||||
|
run.IsItalic = paragraph.IsItalic;
|
||||||
|
}
|
||||||
|
if (!run.IsUnderline.HasValue)
|
||||||
|
{
|
||||||
|
run.IsUnderline = paragraph.IsUnderline;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,6 +7,8 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
{
|
{
|
||||||
public static class WordRowExtension
|
public static class WordRowExtension
|
||||||
{
|
{
|
||||||
|
private static readonly int _coefToPoins = 567;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление строки в таблицу
|
/// Добавление строки в таблицу
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -41,7 +43,7 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
if (model.Height.HasValue)
|
if (model.Height.HasValue)
|
||||||
{
|
{
|
||||||
var properties = new TableRowProperties();
|
var properties = new TableRowProperties();
|
||||||
properties.AppendChild(new TableRowHeight() { Val = new UInt32Value(Convert.ToUInt32(model.Height.Value)) });
|
properties.AppendChild(new TableRowHeight() { Val = new UInt32Value(Convert.ToUInt32((model.Height * _coefToPoins).Value)) });
|
||||||
row.AppendChild(properties);
|
row.AppendChild(properties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using DocumentFormat.OpenXml;
|
using DocumentFormat.OpenXml;
|
||||||
using DocumentFormat.OpenXml.Wordprocessing;
|
using DocumentFormat.OpenXml.Wordprocessing;
|
||||||
using ToolsModule.ManagmentExtension;
|
using ToolsOffice.Interfaces;
|
||||||
using ToolsOffice.Interfaces.Word.Models;
|
using ToolsOffice.Interfaces.Word.Models;
|
||||||
|
|
||||||
namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
||||||
@ -30,25 +30,7 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
docRun.AppendChild(new Text { Text = model.Text, Space = SpaceProcessingModeValues.Preserve });
|
docRun.AppendChild(new Text { Text = model.Text });
|
||||||
}
|
|
||||||
paragraph.AppendChild(docRun);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Добавление текста в абзац
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="paragraph"></param>
|
|
||||||
/// <param name="text"></param>
|
|
||||||
public static void AddRun(this Paragraph paragraph, string text)
|
|
||||||
{
|
|
||||||
if (text.IsEmpty())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var docRun = new Run();
|
|
||||||
{
|
|
||||||
docRun.AppendChild(new Text { Text = text, Space = SpaceProcessingModeValues.Preserve });
|
|
||||||
}
|
}
|
||||||
paragraph.AppendChild(docRun);
|
paragraph.AppendChild(docRun);
|
||||||
}
|
}
|
||||||
@ -65,27 +47,49 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (model.FontSize.HasValue || model.IsBold || model.IsItalic || model.IsUnderline)
|
if (model.FontSize.HasValue || model.IsBold.HasValue || model.IsItalic.HasValue || model.IsUnderline.HasValue)
|
||||||
{
|
{
|
||||||
var properties = new RunProperties();
|
var properties = new RunProperties();
|
||||||
|
if (model.FontName.HasValue)
|
||||||
|
{
|
||||||
|
var font = GetFontName(model.FontName.Value);
|
||||||
|
properties.AppendChild(new RunFonts
|
||||||
|
{
|
||||||
|
Ascii = new StringValue(font.Ascii),
|
||||||
|
HighAnsi = new StringValue(font.HighAnsi),
|
||||||
|
ComplexScript = new StringValue(font.ComplexScript)
|
||||||
|
});
|
||||||
|
}
|
||||||
if (model.FontSize.HasValue)
|
if (model.FontSize.HasValue)
|
||||||
{
|
{
|
||||||
properties.AppendChild(new FontSize { Val = new StringValue(model.FontSize.Value.ToString()) });
|
properties.AppendChild(new FontSize { Val = new StringValue((model.FontSize.Value * 2).ToString()) });
|
||||||
|
properties.AppendChild(new FontSizeComplexScript { Val = new StringValue((model.FontSize.Value * 2).ToString()) });
|
||||||
}
|
}
|
||||||
if (model.IsBold)
|
if (model.IsBold.HasValue && model.IsBold.Value)
|
||||||
{
|
{
|
||||||
properties.AppendChild(new Bold());
|
properties.AppendChild(new Bold());
|
||||||
}
|
}
|
||||||
if (model.IsItalic)
|
if (model.IsItalic.HasValue && model.IsItalic.Value)
|
||||||
{
|
{
|
||||||
properties.AppendChild(new Italic());
|
properties.AppendChild(new Italic());
|
||||||
}
|
}
|
||||||
if (model.IsUnderline)
|
if (model.IsUnderline.HasValue && model.IsUnderline.Value)
|
||||||
{
|
{
|
||||||
properties.AppendChild(new Underline());
|
properties.AppendChild(new Underline());
|
||||||
}
|
}
|
||||||
run.AppendChild(properties);
|
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,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,6 +9,8 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
{
|
{
|
||||||
public static class WordTableExtension
|
public static class WordTableExtension
|
||||||
{
|
{
|
||||||
|
private static readonly int _coefToPoins = 567;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление таблицы в тело документа
|
/// Добавление таблицы в тело документа
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -47,8 +49,8 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
|
|
||||||
for(int rowIndex = 0; rowIndex < headerRowsCount; ++rowIndex)
|
for(int rowIndex = 0; rowIndex < headerRowsCount; ++rowIndex)
|
||||||
{
|
{
|
||||||
var header = new ModelWordTableRow();
|
var header = new ModelWordTableRow { Cells = new Queue<ModelWordTableCell>() };
|
||||||
if (model.RowsHeight.ContainsKey(rowIndex))
|
if (model.RowsHeight?.ContainsKey(rowIndex) ?? false)
|
||||||
{
|
{
|
||||||
header.Height = model.RowsHeight[rowIndex];
|
header.Height = model.RowsHeight[rowIndex];
|
||||||
}
|
}
|
||||||
@ -60,8 +62,8 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
}
|
}
|
||||||
for (int i = 0; i < model.Data.Count; ++i)
|
for (int i = 0; i < model.Data.Count; ++i)
|
||||||
{
|
{
|
||||||
var row = new ModelWordTableRow();
|
var row = new ModelWordTableRow { Cells = new Queue<ModelWordTableCell>() };
|
||||||
if (model.RowsHeight.ContainsKey(i + headerRowsCount))
|
if (model.RowsHeight?.ContainsKey(i + headerRowsCount) ?? false)
|
||||||
{
|
{
|
||||||
row.Height = model.RowsHeight[i + headerRowsCount];
|
row.Height = model.RowsHeight[i + headerRowsCount];
|
||||||
}
|
}
|
||||||
@ -87,38 +89,23 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
|
|
||||||
var properties = new TableProperties();
|
var properties = new TableProperties();
|
||||||
|
|
||||||
var tableLook = new TableLook();
|
properties.AppendChild(new TableLook
|
||||||
if (model.LookFirstRow)
|
|
||||||
{
|
{
|
||||||
tableLook.FirstRow = new OnOffValue(model.LookFirstRow);
|
FirstRow = new OnOffValue(model.LookFirstRow),
|
||||||
}
|
FirstColumn = new OnOffValue(model.LookFirstColumn),
|
||||||
if (model.LookFirstColumn)
|
LastRow = new OnOffValue(model.LookLastRow),
|
||||||
{
|
LastColumn = new OnOffValue(model.LookLastColumn),
|
||||||
tableLook.FirstColumn = new OnOffValue(model.LookFirstColumn);
|
NoHorizontalBand = new OnOffValue(model.LookNoHorizontalBand),
|
||||||
}
|
NoVerticalBand = new OnOffValue(model.LookNoVerticalBand)
|
||||||
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();
|
var tableBorders = new TableBorders();
|
||||||
tableBorders.AddBorder(model, new TopBorder());
|
tableBorders.AddBorder(model, new TopBorder());
|
||||||
tableBorders.AddBorder(model, new BottomBorder());
|
tableBorders.AddBorder(model, new BottomBorder());
|
||||||
tableBorders.AddBorder(model, new LeftBorder());
|
tableBorders.AddBorder(model, new LeftBorder());
|
||||||
tableBorders.AddBorder(model, new RightBorder());
|
tableBorders.AddBorder(model, new RightBorder());
|
||||||
|
tableBorders.AddBorder(model, new InsideHorizontalBorder());
|
||||||
|
tableBorders.AddBorder(model, new InsideVerticalBorder());
|
||||||
|
|
||||||
properties.AppendChild(tableBorders);
|
properties.AppendChild(tableBorders);
|
||||||
|
|
||||||
@ -139,7 +126,7 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
var tableGrid = new TableGrid();
|
var tableGrid = new TableGrid();
|
||||||
foreach (var grid in model.ColumnWidths)
|
foreach (var grid in model.ColumnWidths)
|
||||||
{
|
{
|
||||||
tableGrid.AppendChild(new GridColumn() { Width = new StringValue(grid.ToString()) });
|
tableGrid.AppendChild(new GridColumn() { Width = new StringValue((grid.Value * _coefToPoins).ToString()) });
|
||||||
}
|
}
|
||||||
table.AppendChild(tableGrid);
|
table.AppendChild(tableGrid);
|
||||||
}
|
}
|
||||||
@ -160,6 +147,10 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
{
|
{
|
||||||
borderType.Val = (BorderValues)Enum.Parse(typeof(BorderValues), model.BorderType.Value.ToString());
|
borderType.Val = (BorderValues)Enum.Parse(typeof(BorderValues), model.BorderType.Value.ToString());
|
||||||
}
|
}
|
||||||
|
if (model.BorderWidth.HasValue)
|
||||||
|
{
|
||||||
|
borderType.Size = new UInt32Value(Convert.ToUInt32(model.BorderWidth.Value));
|
||||||
|
}
|
||||||
tableBorders.AppendChild(borderType);
|
tableBorders.AppendChild(borderType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +163,10 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static ModelWordTableCell CreateHeaderCell(ModelWordTable model, int rowIndex, int columnIndex)
|
private static ModelWordTableCell CreateHeaderCell(ModelWordTable model, int rowIndex, int columnIndex)
|
||||||
{
|
{
|
||||||
var cell = new ModelWordTableCell();
|
var cell = new ModelWordTableCell
|
||||||
|
{
|
||||||
|
Width = model.ColumnWidths.ContainsKey(columnIndex) ? model.ColumnWidths[columnIndex] : null
|
||||||
|
};
|
||||||
var elem = model.Headers.FirstOrDefault(x => x.ColumnIndex == columnIndex && x.RowIndex == rowIndex);
|
var elem = model.Headers.FirstOrDefault(x => x.ColumnIndex == columnIndex && x.RowIndex == rowIndex);
|
||||||
if (elem != default)
|
if (elem != default)
|
||||||
{
|
{
|
||||||
@ -187,6 +181,9 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
};
|
};
|
||||||
paragraph.WordTexts.Enqueue(new ModelWordText
|
paragraph.WordTexts.Enqueue(new ModelWordText
|
||||||
{
|
{
|
||||||
|
FontSize = 14,
|
||||||
|
FontName = Interfaces.FontNames.TimesNewRoman,
|
||||||
|
IsBold = true,
|
||||||
Text = elem.Header
|
Text = elem.Header
|
||||||
});
|
});
|
||||||
cell.Texts.Enqueue(paragraph);
|
cell.Texts.Enqueue(paragraph);
|
||||||
@ -220,11 +217,11 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
private static ModelWordTableCell CreateCell(ModelWordTable model, int rowIndex, int columnIndex)
|
private static ModelWordTableCell CreateCell(ModelWordTable model, int rowIndex, int columnIndex)
|
||||||
{
|
{
|
||||||
var cell = new ModelWordTableCell();
|
var cell = new ModelWordTableCell();
|
||||||
var union = model.CellUnion.FirstOrDefault(x => x.StartColumnIndex >= columnIndex && x.StartRowIndex >= rowIndex &&
|
var union = model.CellUnion?.FirstOrDefault(x => x.StartColumnIndex >= columnIndex && x.StartRowIndex >= rowIndex &&
|
||||||
x.FinishColumnIndex <= columnIndex && x.FinishRowIndex <= rowIndex);
|
x.FinishColumnIndex <= columnIndex && x.FinishRowIndex <= rowIndex);
|
||||||
if (union != default)
|
if (union != null && union.Value != default)
|
||||||
{
|
{
|
||||||
if (union.StartColumnIndex == columnIndex)
|
if (union.Value.StartColumnIndex == columnIndex)
|
||||||
{
|
{
|
||||||
cell.IsNewMerge = true;
|
cell.IsNewMerge = true;
|
||||||
}
|
}
|
||||||
@ -245,6 +242,8 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
|
|||||||
};
|
};
|
||||||
paragraph.WordTexts.Enqueue(new ModelWordText
|
paragraph.WordTexts.Enqueue(new ModelWordText
|
||||||
{
|
{
|
||||||
|
FontSize = 14,
|
||||||
|
FontName = Interfaces.FontNames.TimesNewRoman,
|
||||||
Text = model.Data[rowIndex][columnIndex]
|
Text = model.Data[rowIndex][columnIndex]
|
||||||
});
|
});
|
||||||
cell.Texts.Enqueue(paragraph);
|
cell.Texts.Enqueue(paragraph);
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
using System;
|
namespace ToolsOffice.Interfaces
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ToolsOffice.Interfaces
|
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Возможные шрифты
|
||||||
|
/// </summary>
|
||||||
public enum FontNames
|
public enum FontNames
|
||||||
{
|
{
|
||||||
TimesNewRoman = 0
|
TimesNewRoman = 0
|
||||||
|
@ -20,12 +20,41 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public double? PageSizeWidth { get; set; }
|
public double? PageSizeWidth { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Отступ от нижнего края
|
||||||
|
/// </summary>
|
||||||
public double? PageMarginBottom { get; set; }
|
public double? PageMarginBottom { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Отступ от верхнего края
|
||||||
|
/// </summary>
|
||||||
public double? PageMarginTop { get; set; }
|
public double? PageMarginTop { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Отступ от левого края
|
||||||
|
/// </summary>
|
||||||
public double? PageMarginLeft { get; set; }
|
public double? PageMarginLeft { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Отступ от правого края
|
||||||
|
/// </summary>
|
||||||
public double? PageMarginRight { get; set; }
|
public double? PageMarginRight { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Расстояние между полосами страницы
|
||||||
|
/// Если свойство MirrorMargins настроено на True, свойство Gutter добавляет дополнительное пространство на внутренние поля.
|
||||||
|
/// В противном случае дополнительное пространство добавляется в левую поля.
|
||||||
|
/// </summary>
|
||||||
|
public double? PageMarginGutter { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Расстояние до верхнего колонтитула
|
||||||
|
/// </summary>
|
||||||
|
public double? PageHeader { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Расстояние до нижнего колонтитула
|
||||||
|
/// </summary>
|
||||||
|
public double? PageFooter { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -25,7 +25,7 @@ namespace ToolsOffice.Interfaces.Word.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Название шрифта
|
/// Название шрифта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FontNames FontName { get; set; }
|
public FontNames? FontName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Жирный
|
/// Жирный
|
||||||
|
@ -10,12 +10,12 @@ namespace ToolsOffice.Interfaces.Word.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Информация по ширине колонок (номер колонки, ширина колонки), отсчет с 0
|
/// Информация по ширине колонок (номер колонки, ширина колонки), отсчет с 0
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Dictionary<int, int> ColumnWidths { get; set; }
|
public Dictionary<int, double> ColumnWidths { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Информация по высоте строк (номер строки, высота строки), отсчет с 0
|
/// Информация по высоте строк (номер строки, высота строки), отсчет с 0
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Dictionary<int, int > RowsHeight { get; set; }
|
public Dictionary<int, double> RowsHeight { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Информация по объединению ячеек
|
/// Информация по объединению ячеек
|
||||||
@ -33,40 +33,45 @@ namespace ToolsOffice.Interfaces.Word.Models
|
|||||||
public List<string[]> Data { get; set; }
|
public List<string[]> Data { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Иной вывод первой строки
|
/// Указывает, что следует применить условное форматирование первой строки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool LookFirstRow { get; set; }
|
public bool LookFirstRow { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Иной вывод первого столбца
|
/// Указывает, что следует применить условное форматирование к первому столбцу
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool LookFirstColumn { get; set; }
|
public bool LookFirstColumn { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Иной вывод последней строки
|
/// Указывает, что следует применять условное форматирование последней строки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool LookLastRow { get; set; }
|
public bool LookLastRow { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Иной вывод последнего столбца
|
/// Указывает, что следует применять условное форматирование последнего столбца
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool LookLastColumn { get; set; }
|
public bool LookLastColumn { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Указывает, что условное форматирование горизонтальной полосы не должно применяться
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool LookNoHorizontalBand { get; set; }
|
public bool LookNoHorizontalBand { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Указывает, что условное форматирование вертикальной полосы не должно применяться
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool LookNoVerticalBand { get; set; }
|
public bool LookNoVerticalBand { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Тип рамки таблицы
|
/// Тип рамки таблицы
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TypeWordTableBorder? BorderType { get; set; }
|
public TypeWordTableBorder? BorderType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Толщина рамки таблицы
|
||||||
|
/// </summary>
|
||||||
|
public int? BorderWidth { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Список строк для таблицы
|
/// Список строк для таблицы
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -7,6 +7,11 @@ namespace ToolsOffice.Interfaces.Word.Models
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModelWordTableCell
|
public class ModelWordTableCell
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина ячейки
|
||||||
|
/// </summary>
|
||||||
|
public double? Width { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Новое объединение ячеек
|
/// Новое объединение ячеек
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -10,7 +10,7 @@ namespace ToolsOffice.Interfaces.Word.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота строки
|
/// Высота строки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int? Height { get; set; }
|
public double? Height { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Список ячеек строки
|
/// Список ячеек строки
|
||||||
|
@ -25,19 +25,24 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int? FontSize { get; set; }
|
public int? FontSize { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Название шрифта
|
||||||
|
/// </summary>
|
||||||
|
public FontNames? FontName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Жирный
|
/// Жирный
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsBold { get; set; } = false;
|
public bool? IsBold { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Курсив
|
/// Курсив
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsItalic { get; set; } = false;
|
public bool? IsItalic { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Подчеркивание
|
/// Подчеркивание
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsUnderline { get; set; } = false;
|
public bool? IsUnderline { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,9 +6,9 @@ namespace ToolsOffice.Interfaces.Word
|
|||||||
public class PageSizes
|
public class PageSizes
|
||||||
{
|
{
|
||||||
private static readonly
|
private static readonly
|
||||||
Dictionary<string, (double Height, double Width, double MarginBottom, double MarginTop, double MarginLeft, double MarginRigth)> _sizes = new()
|
Dictionary<string, (double Height, double Width, double MarginBottom, double MarginTop, double MarginLeft, double MarginRigth, double MarginGutter, double Header, double Footer)> _sizes = new()
|
||||||
{
|
{
|
||||||
{ "А4", (27.94, 21.59, 2, 2, 3, 1.5) }
|
{ "А4", (29.7, 21, 1.5, 3, 2, 2, 0, 1.5, 1.5) }
|
||||||
};
|
};
|
||||||
|
|
||||||
public static List<string> Sizes => _sizes.Keys.ToList();
|
public static List<string> Sizes => _sizes.Keys.ToList();
|
||||||
@ -40,5 +40,11 @@ namespace ToolsOffice.Interfaces.Word
|
|||||||
public double? PageMarginLeft => _hasKey ? _sizes[_key].MarginLeft : null;
|
public double? PageMarginLeft => _hasKey ? _sizes[_key].MarginLeft : null;
|
||||||
|
|
||||||
public double? PageMarginRight => _hasKey ? _sizes[_key].MarginRigth : null;
|
public double? PageMarginRight => _hasKey ? _sizes[_key].MarginRigth : null;
|
||||||
|
|
||||||
|
public double? PageMarginGutter => _hasKey ? _sizes[_key].MarginGutter : null;
|
||||||
|
|
||||||
|
public double? PageHeader => _hasKey ? _sizes[_key].Header : null;
|
||||||
|
|
||||||
|
public double? PageFooter => _hasKey ? _sizes[_key].Footer : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,15 +1,16 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
</PropertyGroup>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DocumentFormat.OpenXml" Version="2.19.0" />
|
<PackageReference Include="DocumentFormat.OpenXml" Version="2.19.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ToolsModule\ToolsModule.csproj" />
|
<ProjectReference Include="..\ToolsModule\ToolsModule.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
Loading…
Reference in New Issue
Block a user