Правки по пакету word

This commit is contained in:
kotcheshir73 2022-12-19 11:16:24 +04:00
parent 6c2bb49d4d
commit a17e888901
4 changed files with 0 additions and 145 deletions

View File

@ -3,7 +3,6 @@ using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using System.IO;
using ToolsOffice.Implements.WordOpenXML.Extensions;
using ToolsOffice.Implements.WordOpenXML.Models;
using ToolsOffice.Interfaces.Word;
using ToolsOffice.Interfaces.Word.Models;
@ -19,20 +18,11 @@ namespace ToolsOffice.Implements.WordOpenXML
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 (doc != null)
{
mainPart.AddParts(doc.WordDocumentParts);
}
}
public override void CreateParagraph(ModelWordParagraph model)

View File

@ -1,34 +1,12 @@
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
{
/// <summary>
/// Добавление общих элементов документа
/// </summary>
/// <param name="mainPart"></param>
/// <param name="parts"></param>
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);
}
/// <summary>
/// Добавление общих настроек документа
/// </summary>
@ -87,83 +65,5 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions
body.AppendChild(properties);
}
private static void CreateDocumentSettingsPart(WordDocumentParts parts, MainDocumentPart mainPart)
{
if (parts.DocumentSettings.IsNotEmpty())
{
var settings = mainPart.AddNewPart<DocumentSettingsPart>();
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<FontTablePart>();
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<NumberingDefinitionsPart>();
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<StyleDefinitionsPart>();
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<ThemePart>();
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<WebSettingsPart>();
settings.WebSettings = new WebSettings
{
InnerXml = parts.WebSettings
};
settings.WebSettings.Save();
}
}
}
}

View File

@ -1,18 +0,0 @@
using ToolsOffice.Interfaces.Word.Models;
namespace ToolsOffice.Implements.WordOpenXML.Models
{
public class WordCreateDocument
{
public WordDocumentParts WordDocumentParts { get; set; }
public static WordCreateDocument Create(ModelWordDocument model)
{
if (model == null)
{
return null;
}
return new WordCreateDocument();
}
}
}

View File

@ -1,17 +0,0 @@
namespace ToolsOffice.Implements.WordOpenXML.Models
{
public class WordDocumentParts
{
public string DocumentSettings { get; set; }
public string FontTable { get; set; }
public string NumberingDefinitions { get; set; }
public string StyleDefinitions { get; set; }
public string Theme { get; set; }
public string WebSettings { get; set; }
}
}