Replace string in WordDocument with another document, pages are mixed up

I'm having some problems in replacing a string (TAG) in a word document (TEMPLATE) with another word document that has 3 pages (SUB-DOCUMENT). When the TAG is replaced the pages from the second document are mixed up.

TEMPLATE Document contains a TAG (<![Buildings]!>) that needs to be replaced with a SUB-DOCUMENT

SUB-DOCUMENT is a word document with 3 pages and some tables.

I've attached a sample Console App to reproduce this problem.

In output.docx we can see that the pages from SUB-DOCUMENT are mixed up. page 2 is page 1, page 3 is page 2 and page 1 is page 3.

Also in some cases I see empty paragraphs added to the final document

Thanks





Attachment: ReplaceTagWord_578fbbf1.rar

6 Replies

SB Sneha Biju Syncfusion Team February 5, 2024 09:52 AM UTC

Hi Pop,

We have reproduced the reported problem “Replace with another document is not working properly for Word documents” in our end. We will validate this issue and update you with more details by mid of this week.

Regards,
Sneha.



PI Pop Ioan Mihai February 5, 2024 10:13 AM UTC

Hi, 

Thanks for your reply. The problem is related to the structure of the documents. From my research  I've found out that if for example the SUB DOCUMENT is a document with 3 pages with just one text on each page is working fine.

Maybe this will help on your investigation.

Thanks



SB Sneha Biju Syncfusion Team February 6, 2024 01:05 PM UTC

Pop, thank you for providing the details. As mentioned earlier, we will update you with more details by mid of this week.



SB Suriya Balamurugan Syncfusion Team February 7, 2024 03:45 PM UTC

Pop, we have confirmed that the reported issue with “Content misplaced in DOCX document while replacing text with another document” is a defect and we have logged a defect report. We will include the fix for this defect in our weekly NuGet release, which is estimated to be available on two weeks. We will let you know once the fix is included in the weekly release.

The status of this bug can be tracked through the below link:
https://www.syncfusion.com/feedback/50695/content-misplaced-in-docx-document-while-replacing-text-with-another-document

Disclaimer: Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.

Regarding - Also in some cases I see empty paragraphs added to the final document:
We have ensured that only the empty paragraphs present in the template and source documents are preserved in the final document. No additional empty paragraphs are added.



SB Sneha Biju Syncfusion Team February 20, 2024 02:30 PM UTC

Pop, as promised earlier, we have included the fix for the reported bug with “Content misplaced in DOCX document while replacing text with another document in our latest weekly NuGet release (v24.2.7).

Root cause of the issue:
The source document contains multiple sections beginning with tables. When replacing text in a destination document with source document, the found text owner paragraph index differs for each section's content in the source document. So, preserving the content of the last section first, followed by that of the first section, leads to misplaced content.

Please use the below link to download our latest weekly NuGet:
https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core/24.2.7

The status of this bug task can be tracked through the below link:
https://www.syncfusion.com/feedback/50695/content-misplaced-in-docx-document-while-replacing-text-with-another-document

Note: We will include this fix in our 2024 Volume 1 Main release, which will be available in the end of March 2024.



PI Pop Ioan Mihai February 28, 2024 12:10 PM UTC

Hi, thanks for the update.

Everything is working fine now.

Sorry for the late update, I was in vacation.


Thanks


Loader.
Up arrow icon