a:sp (Shape)
Represents a shape object in DrawingML, including rectangles, ellipses, and preset shapes with geometry and appearance properties.
Description
a:sp is the DrawingML shape element that represents a visual shape object. It is defined in ECMA-376 Part 1 §20.1.2.5.1.
Shapes are fundamental drawing objects that can be rectangles, circles, ellipses, or custom geometries. Every shape has geometry (defining the visual outline), visual properties (fill, line, shadow), and optional text body for text content. Shapes can be nested within group shapes.
Attributes
| Attribute | Type | Possible Values | Description |
|---|---|---|---|
| (none) | - | - | All properties are defined through child elements. |
Examples
Rectangle Shape with Blue Fill
<p:sp xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<p:nvSpPr>
<p:cNvPr id="1" name="Rectangle 1"/>
<p:cNvSpPr/>
<p:nvPr/>
</p:nvSpPr>
<p:spPr>
<a:xfrm>
<a:off x="1000" y="1000"/>
<a:ext cx="2000000" cy="1000000"/>
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst/>
</a:prstGeom>
<a:solidFill>
<a:srgbClr val="0070C0"/>
</a:solidFill>
</p:spPr>
<p:txBody>
<a:bodyPr/>
<a:lstStyle/>
<a:p/>
</p:txBody>
</p:sp>
using DocumentFormat.OpenXml.Presentation;
using DocumentFormat.OpenXml.Drawing;
var shape = new Shape();
var nvSpPr = new NonVisualShapeProperties();
nvSpPr.Append(new NonVisualDrawingProperties { Id = 1, Name = "Rectangle 1" });
nvSpPr.Append(new NonVisualShapeDrawingProperties());
nvSpPr.Append(new ShapeNonVisualProperties());
shape.Append(nvSpPr);
var spPr = new ShapeProperties();
var xfrm = new Transform2D();
xfrm.Append(new Offset { X = 1000, Y = 1000 });
xfrm.Append(new Extents { Cx = 2000000, Cy = 1000000 });
spPr.Append(xfrm);
var prstGeom = new PresetGeometry { Preset = ShapeTypeValues.Rectangle };
prstGeom.Append(new AdjustmentValueList());
spPr.Append(prstGeom);
var fill = new SolidFill();
fill.Append(new RgbColorModelHex { Val = "0070C0" });
spPr.Append(fill);
shape.Append(spPr);
var txBody = new TextBody();
txBody.Append(new BodyProperties());
txBody.Append(new ListStyle());
txBody.Append(new Paragraph());
shape.Append(txBody);
Ellipse with Red Outline
<p:sp xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<p:nvSpPr>
<p:cNvPr id="2" name="Ellipse 1"/>
<p:cNvSpPr/>
<p:nvPr/>
</p:nvSpPr>
<p:spPr>
<a:xfrm>
<a:off x="2000000" y="2000000"/>
<a:ext cx="1500000" cy="1500000"/>
</a:xfrm>
<a:prstGeom prst="ellipse">
<a:avLst/>
</a:prstGeom>
<a:noFill/>
<a:ln w="50800">
<a:solidFill>
<a:srgbClr val="FF0000"/>
</a:solidFill>
</a:ln>
</p:spPr>
<p:txBody>
<a:bodyPr/>
<a:lstStyle/>
<a:p/>
</p:txBody>
</p:sp>
var shape = new Shape();
var nvSpPr = new NonVisualShapeProperties();
nvSpPr.Append(new NonVisualDrawingProperties { Id = 2, Name = "Ellipse 1" });
nvSpPr.Append(new NonVisualShapeDrawingProperties());
nvSpPr.Append(new ShapeNonVisualProperties());
shape.Append(nvSpPr);
var spPr = new ShapeProperties();
var xfrm = new Transform2D();
xfrm.Append(new Offset { X = 2000000, Y = 2000000 });
xfrm.Append(new Extents { Cx = 1500000, Cy = 1500000 });
spPr.Append(xfrm);
var prstGeom = new PresetGeometry { Preset = ShapeTypeValues.Ellipse };
prstGeom.Append(new AdjustmentValueList());
spPr.Append(prstGeom);
spPr.Append(new NoFill());
var ln = new Outline { Width = 50800 };
var lineFill = new SolidFill();
lineFill.Append(new RgbColorModelHex { Val = "FF0000" });
ln.Append(lineFill);
spPr.Append(ln);
var txBody = new TextBody();
txBody.Append(new BodyProperties());
txBody.Append(new ListStyle());
txBody.Append(new Paragraph());
shape.Append(txBody);
Notes
- Every shape must have non-visual properties, shape properties, and a text body
- Preset geometries (rectangle, ellipse, triangle) are easier than custom geometries
- Shapes can be positioned and sized using transform properties
- Text body can be empty if shape doesn’t contain text
- Outline width is in EMUs (914400 EMUs = 1 inch)