56 lines
1.7 KiB
C#
56 lines
1.7 KiB
C#
using DocumentFormat.OpenXml;
|
|
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;
|
|
|
|
namespace ToolsOffice.Implements.WordOpenXML
|
|
{
|
|
public class BuilderWordDocumentOpenXML : BuilderWordDocument
|
|
{
|
|
private WordprocessingDocument _wordDocument;
|
|
|
|
private Body _docBody;
|
|
|
|
private MemoryStream _memoryStream;
|
|
|
|
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)
|
|
{
|
|
_docBody.AddParagraph(model);
|
|
}
|
|
|
|
public override void CreateTable(ModelWordTable model)
|
|
{
|
|
_docBody.AddTable(model);
|
|
}
|
|
|
|
public override Stream SaveDocument(ModelWordDocument info)
|
|
{
|
|
_docBody.AddSectionProperties(info);
|
|
_wordDocument.MainDocumentPart.Document.Save();
|
|
_wordDocument.Close();
|
|
return _memoryStream;
|
|
}
|
|
}
|
|
} |