Replace text with table

1.2k Views Asked by At

I am using C# Novacode Docx library to replace string with table in a section of word file but the table is inserting below paragraph. I want to replace text(#table1#) with table in word file.

I have used this code but it doesn't replace on same location rather then it's inserting below paragraph:

foreach (var paragraph in document.Paragraphs)
{
    paragraph.FindAll("#table1#").ForEach(index => paragraph.InsertTableAfterSelf((t1)));
    document.ReplaceText("#table1#", "");
}

see table Error in word report image

1

There are 1 best solutions below

0
hoang hoa On

You should try:
Step1: you replace "#table1#" by one table in document.
Step2: in your code:
Novacode.Table t = document.Tables[0];
Novacode.Table table = t.InsertTableAfterSelf(numberRow, numberColumn);
t.Remove();