I tried your code but there are issues in my scenario.
When I tried to add this logic with my collection, it has below issues:
- Due to bookmark end, my sections are getting added in opposite direction.
- There is lot of space/lines coming in between sections.
- [[TableEnd]] Tag is coming at the end of all sections
- Basically I want to remove original section including [[TableStart]] and [[TableEnd]] tags from the document itself once all the replicated sections are created. How can I do that?
I have attached output file and Expected output file here so that you can see the difference.
Zip also has changed cs file.
Templates.zip (26.6 KB)
Here is my changed code
ArrayList extractedNodes = AsposeHelper.ExtractContent(bmStart, bmEnd, true);
Document sectionDoc = AsposeHelper.GenerateDocument(mDoc, extractedNodes);
//Clean up Section by removing Start and End Tag
FindReplaceOptions options = new FindReplaceOptions(FindReplaceDirection.Forward);
sectionDoc.Range.Replace("[[TableStart]]", string.Empty, options);
sectionDoc.Range.Replace("[[TableEnd]]", string.Empty, options);
//2. For each Report, replicate Section
foreach (ReportData data in mReports)
{
//Clone the Section so that it can be tag replaced before adding to Original Document
Document clonedSectionDoc = sectionDoc.Clone();
//3. For each tag in Replicated Section, replace them with actual data
//For example, [[REG_NO]] will be replaced by data.RegNo and [[REG_Date]] will be replaced by data.RegDate
clonedSectionDoc.Range.Replace("[[REG_NO]]", data.RegNo, options);
clonedSectionDoc.Range.Replace("[[REG_DATE]]", data.RegDate, options);
mBuilder.MoveTo(bmEnd);
mBuilder.InsertDocument(clonedSectionDoc, ImportFormatMode.KeepSourceFormatting);
}