Insert Table between Two Place Holders in Word Document using C# | Regex Find Replace Options

Consider StartTags as below
string[] StartTag = new string[2];
StartTag[0] = @"$abcstart{";
StartTag[1] = @"$xyzstart{";

trying to find tag Insert table after tags.

currently im able replace for single tag but multiple tag is not supporting in my code, how to do for multiple start tag using regex and FindReplaceOptions - Replacing call back.

Sample code with input and current out put and expected output file attched Source.zip (72.6 KB)

@saranyasrinivasan92,

You can meet this requirement by adding the following C# code changes:

...
...
    // Split the last run that contains the match if there is any text left.
    if ((currentNode != null) && (remainingLength > 0))
    {
        SplitRun((Run)currentNode, remainingLength);
        runs.Add(currentNode);
    }

    //Inserting table after startag
    DocumentBuilder builder = new DocumentBuilder((Document)e.MatchNode.Document);
    Run run = (Run)runs[runs.Count - 1];

    if (run.NextSibling.NodeType == NodeType.Run)
    {
        builder.MoveTo(run.NextSibling);

        DataTable dataTable = GetEmpTable();
        Table table = ImportTableFromDataTable(builder, dataTable, true);
        table.SetBorders(LineStyle.Single, 1.5, Color.Black);
    }

    return ReplaceAction.Skip;
}
        
private static Run SplitRun(Run run, int position)
{
...
...

Hope, this helps.

A post was split to a new topic: Replace a Table in Word DOCX Document with another Table using C# .NET