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

Free Support Forum - aspose.com

HorizontalMerge

Hello,

I’ve made a simple table with 2 rows. This first row has 3 cells while the second has 2 cells with the the first cell being a merged cell.

When I look at the properties of all cells Cell.CellFormat.HorizontalMerge is false for all cells.

How can I tell if a cell is actually a merger of 2 cells?

A sample project can be downloaded from:
https://1drv.ms/u/s!AkCkc0juiTKe2gUK5ALVhY8a8VVj

Thanks, Rob

@robschenkel

Thanks for your inquiry. Please not it is expected behavior. We would like to clarify a bit regarding horizontally merged cells. 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.

Following code demonstrates the described things.

// Create empty document and DocumentBuilder object.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

// Configure DocumentBuilder

builder.CellFormat.Borders.LineStyle = LineStyle.Single;

builder.CellFormat.Borders.Color = Color.Black;

// Build table, with simply wide cells.

// First row will contain simply wide cell and in MS Word it will look like merged.

builder.InsertCell();

builder.CellFormat.Width = 200;

builder.Write("This is simply wide cell");

builder.EndRow();

// Insert the second row

builder.InsertCell();

builder.CellFormat.Width = 100;

builder.InsertCell();

builder.CellFormat.Width = 100;

builder.EndRow();

builder.EndTable();

// Insert few paragraphs between table.

builder.Writeln();

builder.Writeln();

// Build table, with merged cells.

// First row will contain merged cells.

builder.InsertCell();

builder.CellFormat.Width = 100;

builder.CellFormat.HorizontalMerge = CellMerge.First;

builder.Write("This is merged cells");

builder.InsertCell();

builder.CellFormat.Width = 100;

builder.CellFormat.HorizontalMerge = CellMerge.Previous;

builder.EndRow();

// Insert the second row

builder.InsertCell();

builder.CellFormat.Width = 100;

builder.CellFormat.HorizontalMerge = CellMerge.None;

builder.InsertCell();

builder.CellFormat.Width = 100;

builder.CellFormat.HorizontalMerge = CellMerge.None;

builder.EndRow();

builder.EndTable();

// Save output document

doc.Save(@"Test001\out.doc");