Insert a Table in a specific paragraph

Hello, I am trying to write a table in my Word Template, but when I change the template, the table was created on the same place.


I was looking for the tag , but I realized what is the paragraph, is ther a way to do this with a function.

Here part of my code:

DocumentBuilder built = new DocumentBuilder(doc);
built.moveToParagraph(74,0);
//Headers
built.insertCell();

built.getRowFormat().setHeight(12.0);
built.getRowFormat().setHeightRule(HeightRule.length);

// built.getCellFormat().getShading().setBackgroundPatternColor(Color.BLUE);
built.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
built.getFont().setSize(10);
built.getFont().setName(“Calibri”);
built.getFont().setBold(true);

// built.getRowFormat().setHeight(HeightRule.AUTO);
built.getCellFormat().setWidth(12.0);
built.write(“NIVEL”);
built.insertCell();
built.write(“COMPONENTE”);
built.insertCell();
built.write(“CLASE”);
built.insertCell();
built.write(“BIBLIOTECA”);
built.insertCell();
built.write(“SISTEMA”);
built.insertCell();
built.write(“DOCUMENTO”);
built.endRow();

built.getRowFormat().setHeight(30.0);
built.getRowFormat().setHeight(HeightRule.AUTO);
.
.
.
.
the part to tells the cursor where to write the table I know its built.movetoParagraph();
when i try

String fullDoc=doc.getRange().getText();
String tagTab="";
int index=fullDoc.indexOf(tagTab);
built.moveToParagraph(index,0);
I´ve got this message error
" java.lang.IllegalArgumentException: Parameter name: paraIdx"

Thanks !
Hi Martin,

Thanks for your inquiry. We suggest you please use find and replace feature of Aspose.Words to find the text "" and insert the table. Please refer to the following article:

Find and Replace

In your case, we suggest you following solution.

1) Please implement IReplacingCallback interface.
2) In IReplacingCallback.Replacing, create an instance of DocumentBuilder class.
3) Move the cursor to the matched node.
4) Insert the table.

Please check the code example shared in following link.
How to Find and Highlight Text

Thanks!,


I will send you a message when I get the results.

It really works!


Thank you so much.
Hi Martin,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.