Hello,can you give me an example like my picture ?
@Jackins Do you mean generating such document programmatically? If so you can easily achieve this using DocumentBuilder. For example see the following code:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Set paragraph alignment and style.
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
// Insert some title.
builder.Writeln("test");
// Clear paragraph formatting and generate some table. For demonstration purposes generate a dummy table.
builder.ParagraphFormat.ClearFormatting();
Table table = builder.StartTable();
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
builder.InsertCell();
builder.Write($"Cell_{i}_{j}");
}
builder.EndRow();
}
builder.EndTable();
// Merge cells in the second row.
Cell currentCell = table.Rows[1].Cells[1];
currentCell.CellFormat.HorizontalMerge = CellMerge.First;
while (currentCell.NextCell != null)
{
currentCell.NextCell.CellFormat.HorizontalMerge = CellMerge.Previous;
currentCell.NextCell.RemoveAllChildren();
currentCell = currentCell.NextCell;
}
doc.Save(@"C:\Temp\out.docx");
out.docx (7.4 KB)
Please see our documentation for more information:
https://docs.aspose.com/words/net/create-a-table/
https://docs.aspose.com/words/net/working-with-merged-cells/
1 Like
Thanks for your help !
1 Like