We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to detect horizontal merge of table cells using Java

Try to identify the Horizontal Merge using Aspose Word Version 20.2 Not Detecting.only detecting Vertical merge alone.i have attached document.Horizontal Merge.zip (10.4 KB)

Code :
public string printCellMergeType(Aspose.Words.Tables.Cell cell)
bool isHorizontallyMerged = cell.CellFormat.HorizontalMerge != Aspose.Words.Tables.CellMerge.None;
bool isVerticallyMerged = cell.CellFormat.VerticalMerge != Aspose.Words.Tables.CellMerge.None;
String cellLocation = “R” + (cell.ParentRow.ParentTable.IndexOf(cell.ParentRow) + 1) +
“, C” + (cell.ParentRow.IndexOf(cell) + 1);

if (isHorizontallyMerged && isVerticallyMerged)
    return "The cell at " + cellLocation + " is both horizontally and vertically merged";
else if (isHorizontallyMerged)
    return "The cell at " + cellLocation + " is horizontally merged.";
else if (isVerticallyMerged)
    return "The cell at " + cellLocation + " is vertically merged";
    return "The cell at " + cellLocation + " is not merged";


There is no column concept in MS Word’s table. By Microsoft Word design, rows in a table in a Microsoft Word document are completely independent. It means each row can have any number of cells of any width. So, if you imagine first row with one wide cell and second row with two narrow cells, then looking at this document the cell in the first row will appear horizontally merged. But it is not a merged cell; it is just a single wide cell.

Another perfectly valid scenario is when the first row has two cells. First cell has CellMerge.First and second cell has CellMerge.Previous, in this case it is a merged cell. In both cases, the visual appearance in MS Word is exactly the same. Both cases are valid.

Thanks For the Replay. which purpose we can use ‘CellFormat.HorizontalMerge’. How to detect the merge columns any other way is there? We need to find merged columns for validation purpose.


If the table’s cells are merged using CellFormat.HorizontalMerge property, you can detect merged cell. However, you can use Table.ConvertToHorizontallyMergedCells method to convert cells horizontally merged by width to cells merged by HorizontalMerge. Please check the following code example. Hope this helps you.

Document doc = new Document(MyDir + "Horizontal Merge.docx");
foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
    foreach (Cell cell in doc.GetChildNodes(NodeType.Cell, true))