Thank you very much for your inquiry.
string dataDir = "C:\\Temp\\";
// Open an existing document.
Document doc = new Document(dataDir + “template.docx”);
// Fill the fields in the document with user data.
doc.MailMerge.Execute(
new string[] { “a”, “b”, “c”, “d”, “e”, “f” },
new object[] { “First”, “Second”, “”, “Fourth”, “Fifth”, “Sixth” });
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
foreach (Row row in table.Rows)
{
foreach (Cell cell in row.Cells)
{
String csValue = cell.GetText();
<span style="color: green;">// Check if cell text is present or not.</span>
<span style="color: blue;">if</span> (csValue == <span style="color: blue;">null</span> || csValue == <span style="color: rgb(163, 21, 21);">""</span> || csValue == <span style="color: rgb(163, 21, 21);">"\a"</span>)
{
<span style="color: rgb(43, 145, 175);">Row</span> nextRow = (<span style="color: rgb(43, 145, 175);">Row</span>)cell.ParentRow.NextSibling;
<span style="color: blue;">if</span> (nextRow != <span style="color: blue;">null</span>)
{
<span style="color: rgb(43, 145, 175);">Cell</span> cellToMergeInto = (<span style="color: rgb(43, 145, 175);">Cell</span>)nextRow.Cells[cell.ParentRow.IndexOf(cell)].Clone(<span style="color: blue;">true</span>);
<span style="color: blue;">int</span> index = row.Cells.IndexOf(cell);
row.Cells.RemoveAt(index);
row.Cells.Insert(index, cellToMergeInto);
nextRow.Cells.RemoveAt(index);
nextRow.Cells.Insert(index, cell);
cellToMergeInto.CellFormat.VerticalMerge = <span style="color: rgb(43, 145, 175);">CellMerge</span>.First;
cell.CellFormat.VerticalMerge = <span style="color: rgb(43, 145, 175);">CellMerge</span>.Previous;
}
}
}
}
// Saved the document in Word format.
doc.Save(dataDir+“output.docx”);