DepartmentProject/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/BuilderWordDocumentOpenXML.cs

46 lines
1.4 KiB
C#
Raw Normal View History

2022-12-17 23:44:29 +04:00
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using System.IO;
using ToolsOffice.Implements.WordOpenXML.Extensions;
2022-12-17 23:44:29 +04:00
using ToolsOffice.Interfaces.Word;
using ToolsOffice.Interfaces.Word.Models;
namespace ToolsOffice.Implements.WordOpenXML
{
public class BuilderWordDocumentOpenXML : BuilderWordDocument
{
private WordprocessingDocument _wordDocument;
private Body _docBody;
private MemoryStream _memoryStream;
public override void CreateDocument(ModelWordDocument model)
2022-12-17 23:44:29 +04:00
{
_memoryStream = new MemoryStream();
_wordDocument = WordprocessingDocument.Create(_memoryStream, WordprocessingDocumentType.Document);
var mainPart = _wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
_docBody = mainPart.Document.AppendChild(new Body());
}
public override void CreateParagraph(ModelWordParagraph model)
2022-12-17 23:44:29 +04:00
{
_docBody.AddParagraph(model);
2022-12-17 23:44:29 +04:00
}
public override void CreateTable(ModelWordTable model)
2022-12-17 23:44:29 +04:00
{
_docBody.AddTable(model);
2022-12-17 23:44:29 +04:00
}
public override Stream SaveDocument(ModelWordDocument info)
2022-12-17 23:44:29 +04:00
{
_docBody.AddSectionProperties(info);
2022-12-17 23:44:29 +04:00
_wordDocument.MainDocumentPart.Document.Save();
_wordDocument.Close();
return _memoryStream;
}
}
}