Shape in Shape 323

Hi,
I am trying to set alternative text on the shape, as you can see in the code below, but when i open the saved file the alternative text is not set.
Can you please check this out?

Thanks,
Zeljko.

code:

Document doc = new Document(“shapeInShape.docx”);
Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 1, true);
Shape shape2 = (Shape) shape.deepClone(true);
shape2.setAlternativeText(“newAltText”);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveTo(shape);
builder.insertNode(shape2);
shape.remove();
doc.save(“new.docx”);

Hi Zeljko,


Thanks for your inquiry. Please use the following code to fix this issue:
<span style=“font-family: “Courier New”; font-size: 9pt; background-color: rgb(255, 255, 255);”>
<span style=“font-family: “Courier New”; font-size: 9pt; background-color: rgb(255, 255, 255);”>Document doc = <span style=“font-family: “Courier New”; font-size: 9pt; color: rgb(0, 0, 128); font-weight: bold;”>new <span style=“font-family: “Courier New”; font-size: 9pt; background-color: rgb(255, 255, 255);”>Document(<span style=“font-family: “Courier New”; font-size: 9pt; color: rgb(0, 128, 0); font-weight: bold;”>“D:<span style=“font-family: “Courier New”; font-size: 9pt; color: rgb(0, 0, 128); font-weight: bold;”>\<span style=“font-family: “Courier New”; font-size: 9pt; color: rgb(0, 128, 0); font-weight: bold;”>temp<span style=“font-family: “Courier New”; font-size: 9pt; color: rgb(0, 0, 128); font-weight: bold;”>\<span style=“font-family: “Courier New”; font-size: 9pt; color: rgb(0, 128, 0); font-weight: bold;”>shapeInShape.docx”<span style=“font-family: “Courier New”; font-size: 9pt; background-color: rgb(255, 255, 255);”>);
<pre style=“font-family: “Courier New”; font-size: 9pt; background-color: rgb(255, 255, 255);”>Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 1, true);
Shape shape2 = (Shape) shape.deepClone(true);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveTo(shape);
builder.insertNode(shape2);
shape2.setAlternativeText(“newAltText”);
shape.remove();
doc.save(“D:\temp\16.6.0.docx”);
Hope, this helps.

Best regards,

Hi,

It kinda helps, but is this a rule, I mean is this just a workaround or should I always do it like this? And can you tell me whats wrong in my code? I think it should work.

Thanks,
Zeljko.

Hi Zeljko,


Thanks for your inquiry. In this case, the Shape.AlternativeText property seems to work only when the Shape is actually inserted at some place in DOM of Aspose.Words (after builder.insertNode(shape2)).

Best regards,