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

Free Support Forum - aspose.com

Table merge possible bug or incorrect usage?

Hi,

I am trying to design a table as shown below using aspose words:

Cell 1

Cell 2

Cell3

Cell4

Cell5

Cell6

Cell7

Cell8

Cell9

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />My code is as below, unfortuantly i cant get the Cell 2 to merge correctly and when i do it messes up the entire table.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.StartTable();

builder.InsertCell();

builder.CellFormat.VerticalMerge = CellMerge.First;

builder.Write("Cell 1");

builder.InsertCell();

builder.CellFormat.VerticalMerge = CellMerge.First;

builder.Write("Cell 2");

builder.InsertCell();

builder.CellFormat.HorizontalMerge = CellMerge.First;

builder.Write("Cell 3");

builder.InsertCell();

builder.CellFormat.HorizontalMerge = CellMerge.Previous;

builder.EndRow();

builder.InsertCell();

builder.CellFormat.VerticalMerge = CellMerge.Previous;

builder.CellFormat.HorizontalMerge = CellMerge.None;

builder.InsertCell();

builder.CellFormat.VerticalMerge = CellMerge.None; // <= should be set to previous but messes up ??

builder.CellFormat.HorizontalMerge = CellMerge.None;

builder.InsertCell();

builder.Write("Cell 4");

builder.InsertCell();

builder.Write("Cell 5");

builder.EndRow();

builder.InsertCell();

builder.Write("Cell6");

builder.InsertCell();

builder.Write("Cell7");

builder.InsertCell();

builder.Write("Cell8");

builder.InsertCell();

builder.Write("Cell9");

builder.EndRow();

builder.EndTable();

doc.Save("a.doc");

Have I misread the documentation or is this a bug, thanks.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Please try using the following code:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.StartTable();

builder.InsertCell();

builder.CellFormat.VerticalMerge = CellMerge.First;

builder.Write("Cell 1");

builder.InsertCell();

builder.CellFormat.VerticalMerge = CellMerge.First;

builder.Write("Cell 2");

builder.InsertCell();

builder.CellFormat.VerticalMerge = CellMerge.None; //<= You should disable vertical merge

builder.CellFormat.HorizontalMerge = CellMerge.First;

builder.Write("Cell 3");

builder.InsertCell();

builder.CellFormat.HorizontalMerge = CellMerge.Previous;

builder.EndRow();

builder.InsertCell();

builder.CellFormat.VerticalMerge = CellMerge.Previous;

builder.CellFormat.HorizontalMerge = CellMerge.None;

builder.InsertCell();

builder.CellFormat.VerticalMerge = CellMerge.Previous; // <= should be set to previous but messes up ??

builder.CellFormat.HorizontalMerge = CellMerge.None;

builder.InsertCell();

builder.CellFormat.VerticalMerge = CellMerge.None; //<= And here you should disable vertical merge

builder.Write("Cell 4");

builder.InsertCell();

builder.Write("Cell 5");

builder.EndRow();

builder.InsertCell();

builder.Write("Cell6");

builder.InsertCell();

builder.Write("Cell7");

builder.InsertCell();

builder.Write("Cell8");

builder.InsertCell();

builder.Write("Cell9");

builder.EndRow();

builder.EndTable();

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

Changes are highlighted.

Best regards.

Thanks very much for this alexey, I assumed the CellFormat attribute defaulted to None when InsertCell was called.

Thanks again


Chris