public void Process(WordprocessingDocument document, Model documentModel) { var mainPart = document.MainDocumentPart; var imageProcessor = new ImageProcessor(mainPart, this.Logger); var compositeElementProcessor = new CompositeElementProcessor(_engineConfig, imageProcessor, this.Logger); compositeElementProcessor.Process(mainPart.Document.Body, documentModel); foreach (var hp in mainPart.HeaderParts) { compositeElementProcessor.Process(hp.Header, documentModel); } foreach (var fp in mainPart.FooterParts) { compositeElementProcessor.Process(fp.Footer, documentModel); } }
private void ProcessCellsOfRow(TableRow row, Model context) { var compositeElementProcessor = new CompositeElementProcessor(_engineConfig, _imageProcessor, _logger); foreach (var cell in row.Cells()) { compositeElementProcessor.Process(cell, context); } }
private (Paragraph, int) ProcessTemplate( ArrayTemplate template, IReadOnlyCollection <Paragraph> bodyParagraphs, Model context) { if (!(context.Find(template.Start.ModelDescription.Expression) is CollectionModel collection)) { return(null, 0); } var startParagraph = bodyParagraphs.ElementAt(template.Start.Position.ParagraphIndex); var endParagraph = bodyParagraphs.ElementAt(template.End.Position.ParagraphIndex); if (startParagraph != endParagraph) { var s = startParagraph.NextSibling(); while (s != endParagraph) { var t = s; s = t.NextSibling(); t.Remove(); } } var result = new List <OpenXmlElement>(); var compositeElementProcessor = new CompositeElementProcessor(_engineConfig, _imageProcessor, _logger); foreach (var item in collection.Items) { var itemBody = template.OpenXml.CreateBody(); compositeElementProcessor.Process(itemBody, item); result.AddRange(itemBody.ChildElements.Select(e => e.CloneNode(true))); } startParagraph.ReplaceToken(template.Start, Model.Empty, _imageProcessor); var textEnd = endParagraph.ReplaceToken(template.End, Model.Empty, _imageProcessor); foreach (var e in result) { endParagraph.InsertBeforeSelf(e); } return(endParagraph, textEnd); }