Append table row with cloned cells of last row with StructuredDocumentTags

I have a table with a row which contains StructuredDocumentTags. I have to add a new row, which I deepClone(true) from the lastRow. The result looks good: a new row. I iterate over the new StructuredDocumentTags and change the title and tag.

In the second step I iterate over all StructuredDocumentTags - for these of MarkupLevel.CELL I removeAllChildren(...) add a Paragraph and a Run with the needed value. In my debug-Log everything works as expected, I see .

BUT! In the Word application, all rows show only the text of the first (i.e. cloned) SDT! If I repeatedly add new rows, the whole table only shows the values from the first row. Why?

If I inspect the cloned StructuredDocumentTag-Controls in Word, they have the changed titles and tags. Which is correct. Only the shown text is wrong!

When I save the document as a PDF, not as a DOCX … it looks correct as expected!?! Only in the word file it’s wrong.

What’s wrong with the cloned StructuredDocumentTags? The IDs of them where distinct, I didn’t see any explanation for this display.

Please help me :slight_smile: Thanks!

@RLehmann Could you please attach your input and output documents here for testing? We will check the issue and provide you more information.
Probably your SDT has an XML mapping and its value is read from XML. Have you tired removing XML mapping?
https://reference.aspose.com/words/java/com.aspose.words/xmlmapping/#delete

Hi Alexey,

I would be really grateful if you could take a look at this. There is no XML binding.
Interesting, if I click the docx-link below, the Word viewer show the document correct. Please see the PNG link at the bottom, this is how the docx is shown in Word application when I open it locally.

Here is an example Maven file with java source which shows how the cloning is called:

exampleMaven.zip

Template:
template.docx

Result as docx.:
result.docx

Saved as PDF looking correct:
result.pdf

If I open the docx locally I see:

Thanks!

@RLehmann You should reset isShowingPlaceholderText flag in your control. Please see the following modified code:

control.isShowingPlaceholderText(false);
Cell cell = (Cell)control.getFirstChild();
Paragraph para = new Paragraph(doc);
cell.removeAllChildren();
para.appendChild(run);
cell.appendChild(para);

Here are the produced output documents:
out.docx (23.0 KB)
out.pdf (29.5 KB)

Hi Alexey,

thank you! That worked! :slight_smile:

1 Like