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

Free Support Forum - aspose.com

Unwanted cell merged in a row

Hello, ASPOSE Team.

I have a problem with merging fields:

builder.IncertCell();
builder.CellFormat.VerticalMerge = CellMerge.First;
builder.Write("A1");

builder.IncertCell();
builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.Write("B1");

builder.IncertCell();
 builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.Write("C1");

builder.IncertCell();
builder.Write("D1");

builder.EndRow();

builder.IncertCell();
builder.CellFormat.VerticalMerge = CellMerge.Previous;
builder.Write("A2");

builder.IncertCell();
builder.Write("B2");

builder.IncertCell();
builder.Write("C2");

builder.IncertCell();
builder.Write("D2");

Expected result is to be:
A1 | B1C1 | D1
| B2 | C2 | D2

Result as is:
A1 | B1C1D1
| B2| C2 | D2

Are there any workarounds?

Best regards,
Max

Hi Max,

Thanks for your inquiry. Please check following sample code snippet, it will help you to accomplish the task. However if there is some difference in your requirement and our understanding then please share your sample expected Word document here. We will further look into it and will guide you accordingly.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.StartTable();

builder.InsertCell();
builder.CellFormat.Width = 100;
builder.CellFormat.VerticalMerge = CellMerge.First;
builder.Write("A1");

builder.InsertCell();
builder.CellFormat.Width = 100;
builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.Write("B1 C1");

builder.InsertCell();
builder.CellFormat.Width = 100;
builder.CellFormat.HorizontalMerge = CellMerge.Previous;

builder.InsertCell();
builder.CellFormat.Width = 100;
builder.CellFormat.HorizontalMerge = CellMerge.None;
builder.CellFormat.VerticalMerge = CellMerge.None;
builder.Write("D1");

builder.EndRow();

builder.InsertCell();
builder.CellFormat.Width = 100;
builder.CellFormat.VerticalMerge = CellMerge.Previous;
builder.Write("A2");

builder.InsertCell();
builder.CellFormat.Width = 100;
builder.CellFormat.HorizontalMerge = CellMerge.None;
builder.Write("B2");

builder.InsertCell();
builder.CellFormat.Width = 100;
builder.CellFormat.HorizontalMerge = CellMerge.None;
builder.Write("C2");

builder.InsertCell();
builder.CellFormat.Width = 100;
builder.CellFormat.HorizontalMerge = CellMerge.None;
builder.Write("D2");
builder.EndRow();
builder.EndTable();

doc.Save("Tabletest.docx");

Best Regards,

Tilal Ahmad
Aspose - File Format APIs

Keep in touch! We’re on Twitter and Facebook