@Manasahr You can easily modify the provided code to meat your requirements:
Document doc = new Document(@"C:\Temp\in.docx");
// Get paragraphs with "Sage Table Reference" style applied.
List<Paragraph> paragraphs = doc.GetChildNodes(NodeType.Paragraph, true).Cast<Paragraph>()
.Where(p => p.ParagraphFormat.StyleName == "Sage Table Reference").ToList();
foreach (Paragraph p in paragraphs)
{
// The the table before the "Sage Table Reference" paragraph
Table table = p.PreviousSibling as Table;
// Check whether the table exsists.
if (table != null)
{
// Create an empty row.
Row emptyRow = (Row)table.LastRow.Clone(true);
emptyRow.FirstCell.RemoveAllChildren();
emptyRow.FirstCell.CellFormat.HorizontalMerge = CellMerge.First;
Cell nextCell = emptyRow.FirstCell.NextSibling as Cell;
while (nextCell != null)
{
nextCell.RemoveAllChildren();
nextCell.CellFormat.HorizontalMerge = CellMerge.Previous;
nextCell = nextCell.NextSibling as Cell;
}
// Put an empty row at the end of the table.
table.AppendChild(emptyRow);
// Copy the paragraph after the table into the last row.
emptyRow.FirstCell.AppendChild(p);
// Remove borders.
emptyRow.RowFormat.Borders.ClearFormatting();
}
}
doc.Save(@"C:\Temp\out.docx");
The code provided earlier provides a basic idea of the implementation. It is not supposed to work out of the box for all your cases.