Search code examples
c#.netasposecaptionaspose.words

how to insert caption to table and figure in aspose.word


I want to create a table of figure and table of tables but first tables and figures should have caption to be Identify.and I need to insert caption to tables and figure


Solution

  • Please try using the following code.

    Document doc = new Document(MyDir + "in.docx"); 
    DocumentBuilder builder = new DocumentBuilder(doc);
    
    builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
    
    // Insert caption above the Table
    builder.MoveTo(doc.FirstSection.Body.Tables[0].PreviousSibling);
    builder.Write("Table: ");
    builder.InsertField(@"SEQ Table \* ARABIC", "");
    
    // Insert caption below the Figure
    builder.MoveToDocumentEnd();
    builder.InsertParagraph();
    builder.Write("Figure: ");
    builder.InsertField(@"SEQ Figure \* ARABIC", "");
    
    doc.UpdateFields();
    
    doc.Save(MyDir + @"17.11.docx");
    

    I work with Aspose as Developer Evangelist.