[]
        
(Showing Draft Content)

Alternative Text

To assist visually impaired individuals in understanding the content of shapes, users can add alternative text (alt text) to shapes. When content is accessed using a screen reader, this associated alternative text is identified and read aloud, enabling users to better understand the shape’s purpose or meaning.

DsExcel.NET provides the Title, AlternativeText, and Decorative properties of the IShape interface, which are used to set the title and content of a shape’s alternative text, or to indicate whether the shape is decorative.

Property

Description

Title

Sets the title for the alternative text of a shape.

AlternativeText

Sets the main content for the shape's alternative text.

Decorative

Indicates whether the shape is decorative. When set to true, the shape is marked as decorative and will generally be ignored by screen readers.

Default value: false.

  • Shapes, as well as pictures, charts, slicers, group shapes, linked pictures, and controls support alternative text.

  • SpreadJS does not support the Decorative property. If a file has the Decorative property set and is exported to SJS or SSJSON format, the Decorative setting will not be retained.

Add Alternative Text

Refer to the following sample code to add alternative text to a shape.

// Create a new workbook.
var workbook = new GrapeCity.Documents.Excel.Workbook();
IWorksheet worksheet = workbook.Worksheets[0];

// Add a rounded rectangle shape.
GrapeCity.Documents.Excel.Drawing.IShape shape = worksheet.Shapes.AddShape(GrapeCity.Documents.Excel.Drawing.AutoShapeType.RoundedRectangle, 10, 10, 200, 100);

// Set alternative text.
shape.Title = "Test Shape";
shape.AlternativeText = "This is a rounded rectangle.";

// Save to an excel file.
workbook.Save("SetShapeAltText.xlsx");

The output is shown in the figure below:

image-20250430-020659

Mark as Decorative

Refer to the following sample code to mark the shape as decorative.

// Create a new workbook.
var workbook = new GrapeCity.Documents.Excel.Workbook();
IWorksheet worksheet = workbook.Worksheets[0];

// Add a rounded rectangle shape.
GrapeCity.Documents.Excel.Drawing.IShape shape = worksheet.Shapes.AddShape(GrapeCity.Documents.Excel.Drawing.AutoShapeType.RoundedRectangle, 10, 10, 200, 100);

// Set alternative text.
shape.Title = "Test Shape";
shape.AlternativeText = "This is a rounded rectangle.";

// When a shape is marked as decorative, the alternative text will be cleared.
shape.Decorative = true;

// Save to an excel file.
workbook.Save("SetShapeAltText.xlsx");

The output is shown in the figure below:

image-20250430-013735