Specifies how a cell in a table is merged with other cells.
Namespace:
Aspose.Words.Tables
Assembly:
Aspose.Words (in Aspose.Words.dll) Version: 20.3
SyntaxPublic Enumeration CellMerge
public enum class CellMerge
Members
| Member name | Value | Description |
---|
| None | 0 |
The cell is not merged.
|
| First | 1 |
The cell is the first cell in a range of merged cells.
|
| Previous | 2 |
The cell is merged to the previous cell horizontally or vertically.
|
ExamplesCreates a table with two rows with cells in the first row horizontally merged.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.Write("Text in merged cells.");
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.EndRow();
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.None;
builder.Write("Text in one cell.");
builder.InsertCell();
builder.Write("Text in another cell.");
builder.EndRow();
builder.EndTable();
ExamplesCreates a table with two columns with cells merged vertically in the first column.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertCell();
builder.CellFormat.VerticalMerge = CellMerge.First;
builder.Write("Text in merged cells.");
builder.InsertCell();
builder.CellFormat.VerticalMerge = CellMerge.None;
builder.Write("Text in one cell");
builder.EndRow();
builder.InsertCell();
builder.CellFormat.VerticalMerge = CellMerge.Previous;
builder.InsertCell();
builder.CellFormat.VerticalMerge = CellMerge.None;
builder.Write("Text in another cell");
builder.EndRow();
builder.EndTable();
ExamplesPrints the horizontal and vertical merge type of a cell.
public void CheckCellsMerged()
{
Document doc = new Document(MyDir + "Table with merged cells.docx");
Table table = (Table) doc.GetChild(NodeType.Table, 0, true);
foreach (Row row in table.Rows.OfType<Row>())
{
foreach (Cell cell in row.Cells.OfType<Cell>())
{
Console.WriteLine(PrintCellMergeType(cell));
}
}
Assert.AreEqual("The cell at R1, C1 is vertically merged",
}
public string PrintCellMergeType(Cell cell)
{
bool isHorizontallyMerged = cell.CellFormat.HorizontalMerge != CellMerge.None;
bool isVerticallyMerged = cell.CellFormat.VerticalMerge != 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";
if (isHorizontallyMerged)
return $"The cell at {cellLocation} is horizontally merged.";
return isVerticallyMerged ? $"The cell at {cellLocation} is vertically merged" : $"The cell at {cellLocation} is not merged";
}
See Also