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

Free Support Forum - aspose.com

How to set and get table title and descriptions using C#

We have the need to read in the AlternativeText and Title properties of a table. In looking at the object model, they are there under the non-public members. Any chance we can get those exposed as public properties soon?

Thanks!

Hi Ron,

Thanks for your query. We had already
logged this issue into our tracking system as “New Feature” request. Your request has also been linked to the appropriate issue.

You will be updated via this forum thread once this feature is available.

The issues you have found earlier (filed as WORDSNET-5890) have been fixed in this Aspose.Words for .NET 18.6 update and this Aspose.Words for Java 18.6 update.

@RonPuckett

Microsoft Word allows you to add alternative text (alt text) to table. This feature makes document to more accessible to users.To add some alt text to a table, select Table > Properties, and in the Table Properties window that appears, click Alt Text.

Starting from Aspose.Words 18.6, you can set the table’s title and description using Table.Title and Table.Description properties.

Following code example shows how to build a nested table and set table’s title and description.

public void CreateNestedTable()
{
    Document doc = new Document();

    // Create the outer table with three rows and four columns
    Table outerTable = CreateTable(doc, 3, 4, "Outer Table");
    // Add it to the document body
    doc.FirstSection.Body.AppendChild(outerTable);

    // Create another table with two rows and two columns
    Table innerTable = CreateTable(doc, 2, 2, "Inner Table");
    // Add this table to the first cell of the outer table
    outerTable.FirstRow.FirstCell.AppendChild(innerTable);

    doc.Save(ArtifactsDir + "Table.CreateNestedTable.docx");
}

/// <summary>
/// Creates a new table in the document with the given dimensions and text in each cell.
/// </summary>
private static Table CreateTable(Document doc, int rowCount, int cellCount, string cellText)
{
    Table table = new Table(doc);

    // Create the specified number of rows
    for (int rowId = 1; rowId <= rowCount; rowId++)
    {
        Row row = new Row(doc);
        table.AppendChild(row);

        // Create the specified number of cells for each row
        for (int cellId = 1; cellId <= cellCount; cellId++)
        {
            Cell cell = new Cell(doc);
            row.AppendChild(cell);
            // Add a blank paragraph to the cell
            cell.AppendChild(new Paragraph(doc));

            // Add the text
            cell.FirstParagraph.AppendChild(new Run(doc, cellText));
        }
    }

    // You can add title and description to your table only when added at least one row to the table first
    // This properties are meaningful for ISO / IEC 29500 compliant DOCX documents(see the OoxmlCompliance class)
    // When saved to pre-ISO/IEC 29500 formats, the properties are ignored
    table.Title = "Aspose table title";
    table.Description = "Aspose table description";

    return table;
}