s1ny
September 8, 2015, 9:58am
1
I have table like this
How can i do this table , with 2-level hierarchy or more /
header
first
second
third
I have one idea : MoveTo current Cell ,Add New Cell , and add this lower cells(first,second,third ) and header cell (header) in this. This
is what i want to result.
Hi Ilya,
Thanks for your inquiry. Please see attached sample input/output Word documents and following code to achieve this requirement.
Document doc = new Document(MyDir + @"in.docx");
Table tab = (Table)doc.GetChildNodes(NodeType.Table, true)[0];
Row clone = (Row)tab.FirstRow.Clone(true);
tab.Rows.Add(clone);
foreach (Cell cell in tab.FirstRow)
{
cell.RemoveAllChildren();
if (cell.IsFirstCell)
{
cell.CellFormat.HorizontalMerge = CellMerge.First;
cell.Paragraphs.Add(new Paragraph(doc));
cell.FirstParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Center;
cell.FirstParagraph.Runs.Add(new Run(doc, "header"));
}
else
{
cell.CellFormat.HorizontalMerge = CellMerge.Previous;
}
}
doc.Save(MyDir + @"15.8.0.doc");
Hope, this helps.
Best regards,