Free Support Forum - aspose.com

Can a table be inserted into a text box object

for (final Shape shape : (Iterable) shapes) {
if (“LEGENDTABLE”.equals(shape.getAlternativeText().trim())) {
final Table table = new Table(doc);
shape.getFirstParagraph().appendChild(table);
}
}

We open a docx, which has a text box, when we try to into a table into it, the error is thrown that “java.lang.IllegalArgumentException: Cannot insert a node of this type at this location”.

Can we insert a table into a text box shape object?

Thanks

Hi,


Thanks for your inquiry. Please use the following code snippet to achieve your requirements. Hope this helps you. If you still face problem, please share your document here for investigation purposes.

//Create Document and DocumentBuilder

Document doc = new Document(MyDir + "in.docx");

DocumentBuilder builder = new DocumentBuilder(doc);

Shape textBox = (Shape)doc.getChild(NodeType.SHAPE, 0, true);

//Move DocumentBuilder cursor to paragraph inserted into the shape

builder.moveTo(textBox.getFirstParagraph());

//Start table

Table table = builder.startTable();

//Insert one cell into the table

builder.insertCell();

builder.write("Aspose.Words");

builder.endRow();

builder.endTable();

textBox.appendChild(table);

doc.save(MyDir + "out.docx");