I have created a very simple template (see attached file), import it, add my contents and later try to do a MailMerge.
However, the call to this function fails with the following exception:System.ArgumentException
HResult=0x80070057
Message=The document element is already associated with a parent.
Parametername: item
Source=Telerik.Windows.Documents.Flow
StackTrace:
at Telerik.Windows.Documents.Flow.Model.Collections.DocumentElementCollection`2.VerifyDocumentElementOnInsert(T item) in c:\DeveloperTooling_Agent13\_work\91\s\Documents\Flow\Flow\Model\Collections\DocumentElementCollection.cs:line 69
at Telerik.Windows.Documents.Core.Data.DocumentElementCollectionBase`2.InsertRange(Int32 index, IEnumerable`1 items) in c:\DeveloperTooling_Agent13\_work\91\s\Documents\Core\Core\Core\Data\DocumentElementCollectionBase.cs:line 129
at Telerik.Windows.Documents.Flow.Model.InlineRangeEditor.InsertInlinesInRange(InlineBase start, IEnumerable`1 inlines) in c:\DeveloperTooling_Agent13\_work\91\s\Documents\Flow\Flow\Model\InlineRangeEditor.cs:line 132
at Telerik.Windows.Documents.Flow.Model.Fields.FieldInfo.UpdateFieldCore(FieldUpdateContext context) in c:\DeveloperTooling_Agent13\_work\91\s\Documents\Flow\Flow\Model\Fields\FieldInfo.cs:line 236
at Telerik.Windows.Documents.Flow.Model.Fields.FieldInfo.UpdateFieldInternal(FieldUpdateContext context) in c:\DeveloperTooling_Agent13\_work\91\s\Documents\Flow\Flow\Model\Fields\FieldInfo.cs:line 186
at Telerik.Windows.Documents.Flow.Model.MailMergeProcessor.ExecuteMailMerge(RadFlowDocument document, Object record) in c:\DeveloperTooling_Agent13\_work\91\s\Documents\Flow\Flow\Model\MailMergeProcessor.cs:line 57
at Telerik.Windows.Documents.Flow.Model.MailMergeProcessor.Execute(RadFlowDocument document, IEnumerable collection) in c:\DeveloperTooling_Agent13\_work\91\s\Documents\Flow\Flow\Model\MailMergeProcessor.cs:line 25
at Telerik.Windows.Documents.Flow.Model.RadFlowDocument.MailMerge(IEnumerable collection) in c:\DeveloperTooling_Agent13\_work\91\s\Documents\Flow\Flow\Model\RadFlowDocument.cs:line 337
at JOIM.TextExport.DocumentGenerator.Export(String outputPath) in P:\Tolaris\JOIM.Common\JOIM.TextExport\DocumentGenerator.cs:line 581
using Telerik.Windows.Documents.Flow.FormatProviders.Docx; using Telerik.Windows.Documents.Flow.Model; using Telerik.Windows.Documents.Spreadsheet.Model; ... using (StreamfileStream = File.Open(templatePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { var provider = newDocxFormatProvider(); _document = provider.Import(fileStream); } ... _document = Document.MailMerge(new [] { MergeFieldData });
string html = File.ReadAllText("Source.html");
string newHtml = html.Replace("<br>", "[br]");
File.WriteAllText("NewSource.html", newHtml);
using (Stream stream = File.OpenRead("NewSource.html"))
{
HtmlFormatProvider htmlFormatProvider = new HtmlFormatProvider();
flowDocument = htmlFormatProvider.Import(stream);
TxtFormatProvider txtFormatProvider = new TxtFormatProvider();
string text = txtFormatProvider.Export(flowDocument);
string newText = text.Replace("[br]", "\r\n");
}
Wrong exported paragraph indentation when the paragraph is in a table cell.
Workaround: Iterate table`s paragraphs and set the negative indentations to zero:
IEnumerable<Table> tables = this.document.EnumerateChildrenOfType<Table>();
foreach (Table table in tables)
{
IEnumerable<Paragraph> paragraphs = table.EnumerateChildrenOfType<Paragraph>();
foreach (Paragraph paragraph in paragraphs)
{
if (paragraph.Indentation.LeftIndent < 0)
{
paragraph.Indentation.LeftIndent = 0;
}
}
}
Revisions in WordprocessingML provide a mechanism for storing information about the evolution of the
document (i.e. the set of modifications made to a document by one or more authors).
<w:pict ...>
<v:shape ...>
<v:fill opacity="39151f"/>
<v:path .../>
<w10:wrap anchorx="page" anchory="page"/>
</v:shape>
</w:pict>