Free Support Forum - aspose.com

Aspose word dynamic table

Hello

I have a word template,i want to insert a table dynamicly to the word document with multiple headers.

Please check the atatched template .I need to place dynamic(need to generate from code) a table with multiple headers(like merge of some rows) .

Please help me with this.

Hi Anju,


Thanks for your inquiry. In Aspose.Words, merged cells are represented by CellFormat.HorizontalMerge and CellFormat.VerticalMerge. The CellFormat.HorizontalMerge property describes if the cell is part of a horizontal merge of cells. Likewise the CellFormat.VerticalMerge property describes if the cell is a part of a vertical merge of cells.

Please check the following code snippet for your kind reference.

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:#2B91AF;mso-no-proof:yes”>Document<span style=“font-size:10.0pt;font-family:“Courier New”;mso-no-proof:yes”> doc = new Document();<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);

builder.InsertCell();

builder.CellFormat.VerticalMerge = CellMerge.First;

builder.CellFormat.HorizontalMerge = CellMerge.First;

builder.Write("Ply");

builder.InsertCell();

builder.CellFormat.HorizontalMerge = CellMerge.First;

builder.CellFormat.VerticalMerge = CellMerge.None;

builder.Write("Paper");

builder.InsertCell();

builder.CellFormat.HorizontalMerge = CellMerge.Previous;

builder.CellFormat.VerticalMerge = CellMerge.None;

builder.InsertCell();

builder.InsertCell();

builder.CellFormat.HorizontalMerge = CellMerge.Previous;

builder.CellFormat.VerticalMerge = CellMerge.None;

builder.InsertCell();

builder.EndRow();

//Second Row

builder.InsertCell();

builder.CellFormat.VerticalMerge = CellMerge.Previous;

builder.CellFormat.HorizontalMerge = CellMerge.None;

builder.InsertCell();

builder.CellFormat.HorizontalMerge = CellMerge.None;

builder.CellFormat.VerticalMerge = CellMerge.None;

builder.Write("Color");

builder.InsertCell();

builder.CellFormat.HorizontalMerge = CellMerge.None;

builder.CellFormat.VerticalMerge = CellMerge.None;

builder.Write("Wt");

builder.InsertCell();

builder.CellFormat.HorizontalMerge = CellMerge.None;

builder.CellFormat.VerticalMerge = CellMerge.None;

builder.Write("Grade");

builder.EndRow();

//Third Row

builder.InsertCell();

builder.CellFormat.VerticalMerge = CellMerge.None;

builder.CellFormat.HorizontalMerge = CellMerge.None;

builder.Write("Cell text");

builder.InsertCell();

builder.CellFormat.HorizontalMerge = CellMerge.None;

builder.CellFormat.VerticalMerge = CellMerge.None;

builder.Write("Cell text");

builder.InsertCell();

builder.CellFormat.HorizontalMerge = CellMerge.None;

builder.CellFormat.VerticalMerge = CellMerge.None;

builder.Write("Cell text");

builder.InsertCell();

builder.CellFormat.HorizontalMerge = CellMerge.None;

builder.CellFormat.VerticalMerge = CellMerge.None;

builder.Write("Cell text");

builder.EndRow();

builder.EndTable();

doc.Save(MyDir + "out.docx");



Please read following documentation link for more detail:
http://www.aspose.com/docs/display/wordsnet/Working+with+Merged+Cells

For an easy method of achieving your requirement, please see "MergeCells" method from above article.