Hi
Thanks for your request.
1. 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.
Here is simple code, which 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 contains 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 contains 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");
2. Vertically merged
cells. You can create vertically merged cells only using
CellFormat.VerticalMerge. The first cell in the merged region should have
VerticalMerge = CellMerge.First, all
other cells in the merged region should have CellMerge.Previous. Simple code, which shows how to create table
with vertically merged cells is shown below:
// 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 vertacally merged cells.
builder.InsertCell();
builder.CellFormat.Width = 100;
builder.CellFormat.VerticalMerge = CellMerge.First;
builder.Write("This is
vertically merged cells");
builder.InsertCell();
builder.CellFormat.Width = 100;
builder.CellFormat.VerticalMerge = CellMerge.None;
builder.EndRow();
// Insert the second row
builder.InsertCell();
builder.CellFormat.Width = 100;
builder.CellFormat.VerticalMerge = CellMerge.Previous;
builder.InsertCell();
builder.CellFormat.Width = 100;
builder.CellFormat.VerticalMerge = CellMerge.None;
builder.EndRow();
builder.EndTable();
// Save output document
doc.Save(@"Test001\out.doc");
Hope this could help you. Please let me know in case of any
issues. I will be glad to help you.
Best regards.