PowerPoint.Shape class
Stellt ein einzelnes Shape auf der Folie dar.
- Extends
Hinweise
Verwendet von
- PowerPoint.ShapeCollection: addGeometricShape, addLine, addTextBox, getItem, getItemAt, getItemOrNullObject, Elemente
- PowerPoint.ShapeScopedCollection: getItem, getItemAt, getItemOrNullObject, Elemente
- PowerPoint.TextFrame: getParentShape
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-shapes-by-type.yaml
// Changes the transparency of every geometric shape in the slide.
await PowerPoint.run(async (context) => {
// Get the type of shape for every shape in the collection.
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
shapes.load("type");
await context.sync();
// Change the shape transparency to be halfway transparent.
shapes.items.forEach((shape) => {
if (shape.type === PowerPoint.ShapeType.geometricShape) {
shape.fill.transparency = 0.5;
}
});
await context.sync();
});
Eigenschaften
| context | Der dem Objekt zugeordnete Anforderungskontext. Dadurch wird der Prozess des Add-Ins mit dem Prozess der Office-Hostanwendung verbunden. |
| custom |
Gibt eine Auflistung benutzerdefinierter XML-Teile in der Form zurück. |
| fill | Gibt die Füllungsformatierung dieser Form zurück. |
| height | Gibt die Höhe des Shapes in Punkten an. Löst eine |
| id | Ruft die eindeutige ID des Shapes ab. |
| left | Der Abstand in Punkten von der linken Seite des Shapes zur linken Seite der Folie. |
| line |
Gibt die Linienformatierung dieser Form zurück. |
| name | Gibt den Namen dieses Shapes an. |
| tags | Gibt eine Auflistung von Tags in der Form zurück. |
| text |
Gibt das PowerPoint.TextFrame-Objekt dieses |
| top | Der Abstand in Punkten vom oberen Rand des Shapes bis zum oberen Rand der Folie. |
| type | Gibt den Typ dieser Form zurück. Weitere Informationen finden Sie unter PowerPoint.ShapeType . |
| width | Gibt die Breite des Shapes in Punkten an. Löst eine |
Methoden
| delete() | Löscht die Form aus der Formsammlung. Tut nichts, wenn das Shape nicht vorhanden ist. |
| get |
Gibt das übergeordnete PowerPoint.Slide-Objekt zurück, das dies |
| get |
Gibt das übergeordnete PowerPoint.SlideLayout-Objekt zurück, das dies |
| get |
Gibt das übergeordnete PowerPoint.SlideLayout-Objekt zurück, das dies |
| get |
Gibt das übergeordnete PowerPoint.SlideMaster-Objekt zurück, das dies |
| get |
Gibt das übergeordnete PowerPoint.SlideMaster-Objekt zurück, das dies |
| get |
Gibt das übergeordnete PowerPoint.Slide-Objekt zurück, das dies |
| load(options) | Stellt einen Befehl zum Laden der angegebenen Eigenschaften des Objekts in die Warteschlange ein. Vor dem Lesen der Eigenschaften müssen Sie " |
| load(property |
Stellt einen Befehl zum Laden der angegebenen Eigenschaften des Objekts in die Warteschlange ein. Vor dem Lesen der Eigenschaften müssen Sie " |
| load(property |
Stellt einen Befehl zum Laden der angegebenen Eigenschaften des Objekts in die Warteschlange ein. Vor dem Lesen der Eigenschaften müssen Sie " |
| toJSON() | Überschreibt die JavaScript-Methode |
Details zur Eigenschaft
context
Der dem Objekt zugeordnete Anforderungskontext. Dadurch wird der Prozess des Add-Ins mit dem Prozess der Office-Hostanwendung verbunden.
context: RequestContext;
Eigenschaftswert
customXmlParts
Gibt eine Auflistung benutzerdefinierter XML-Teile in der Form zurück.
readonly customXmlParts: PowerPoint.CustomXmlPartCollection;
Eigenschaftswert
Hinweise
fill
Gibt die Füllungsformatierung dieser Form zurück.
readonly fill: PowerPoint.ShapeFill;
Eigenschaftswert
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-set-shapes.yaml
// Changes the selected shapes fill color to red.
await PowerPoint.run(async (context) => {
const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
const shapeCount = shapes.getCount();
shapes.load("items/fill/type");
await context.sync();
shapes.items.map((shape) => {
const shapeFillType = shape.fill.type as PowerPoint.ShapeFillType;
console.log(`Shape ID ${shape.id} original fill type: ${shapeFillType}`);
shape.fill.setSolidColor("red");
});
await context.sync();
});
height
Gibt die Höhe des Shapes in Punkten an. Löst eine InvalidArgument Ausnahme aus, wenn sie mit einem negativen Wert festgelegt wird.
height: number;
Eigenschaftswert
number
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-set-shapes.yaml
// Arranges the selected shapes in a line from left to right.
await PowerPoint.run(async (context) => {
const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
const shapeCount = shapes.getCount();
shapes.load("items");
await context.sync();
let maxHeight = 0;
shapes.items.map((shape) => {
shape.load("width,height");
});
await context.sync();
shapes.items.map((shape) => {
shape.left = currentLeft;
shape.top = currentTop;
currentLeft += shape.width;
if (shape.height > maxHeight) maxHeight = shape.height;
});
await context.sync();
currentLeft = 0;
if (currentTop > slideHeight - 200) currentTop = 0;
});
id
Ruft die eindeutige ID des Shapes ab.
readonly id: string;
Eigenschaftswert
string
Hinweise
left
Der Abstand in Punkten von der linken Seite des Shapes zur linken Seite der Folie.
left: number;
Eigenschaftswert
number
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-set-shapes.yaml
// Arranges the selected shapes in a line from left to right.
await PowerPoint.run(async (context) => {
const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
const shapeCount = shapes.getCount();
shapes.load("items");
await context.sync();
let maxHeight = 0;
shapes.items.map((shape) => {
shape.load("width,height");
});
await context.sync();
shapes.items.map((shape) => {
shape.left = currentLeft;
shape.top = currentTop;
currentLeft += shape.width;
if (shape.height > maxHeight) maxHeight = shape.height;
});
await context.sync();
currentLeft = 0;
if (currentTop > slideHeight - 200) currentTop = 0;
});
lineFormat
Gibt die Linienformatierung dieser Form zurück.
readonly lineFormat: PowerPoint.ShapeLineFormat;
Eigenschaftswert
Hinweise
name
Gibt den Namen dieses Shapes an.
name: string;
Eigenschaftswert
string
Hinweise
tags
Gibt eine Auflistung von Tags in der Form zurück.
readonly tags: PowerPoint.TagCollection;
Eigenschaftswert
Hinweise
textFrame
Gibt das PowerPoint.TextFrame-Objekt dieses Shapezurück. Löst eine InvalidArgument Ausnahme aus, wenn das Shape keine TextFrameunterstützt.
readonly textFrame: PowerPoint.TextFrame;
Eigenschaftswert
Hinweise
top
Der Abstand in Punkten vom oberen Rand des Shapes bis zum oberen Rand der Folie.
top: number;
Eigenschaftswert
number
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-set-shapes.yaml
// Arranges the selected shapes in a line from left to right.
await PowerPoint.run(async (context) => {
const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
const shapeCount = shapes.getCount();
shapes.load("items");
await context.sync();
let maxHeight = 0;
shapes.items.map((shape) => {
shape.load("width,height");
});
await context.sync();
shapes.items.map((shape) => {
shape.left = currentLeft;
shape.top = currentTop;
currentLeft += shape.width;
if (shape.height > maxHeight) maxHeight = shape.height;
});
await context.sync();
currentLeft = 0;
if (currentTop > slideHeight - 200) currentTop = 0;
});
type
Gibt den Typ dieser Form zurück. Weitere Informationen finden Sie unter PowerPoint.ShapeType .
readonly type: PowerPoint.ShapeType | "Unsupported" | "Image" | "GeometricShape" | "Group" | "Line" | "Table" | "Callout" | "Chart" | "ContentApp" | "Diagram" | "Freeform" | "Graphic" | "Ink" | "Media" | "Model3D" | "Ole" | "Placeholder" | "SmartArt" | "TextBox";
Eigenschaftswert
PowerPoint.ShapeType | "Unsupported" | "Image" | "GeometricShape" | "Group" | "Line" | "Table" | "Callout" | "Chart" | "ContentApp" | "Diagram" | "Freeform" | "Graphic" | "Ink" | "Media" | "Model3D" | "Ole" | "Placeholder" | "SmartArt" | "TextBox"
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-shapes-by-type.yaml
// Changes the transparency of every geometric shape in the slide.
await PowerPoint.run(async (context) => {
// Get the type of shape for every shape in the collection.
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
shapes.load("type");
await context.sync();
// Change the shape transparency to be halfway transparent.
shapes.items.forEach((shape) => {
if (shape.type === PowerPoint.ShapeType.geometricShape) {
shape.fill.transparency = 0.5;
}
});
await context.sync();
});
width
Gibt die Breite des Shapes in Punkten an. Löst eine InvalidArgument Ausnahme aus, wenn sie mit einem negativen Wert festgelegt wird.
width: number;
Eigenschaftswert
number
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-set-shapes.yaml
// Arranges the selected shapes in a line from left to right.
await PowerPoint.run(async (context) => {
const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
const shapeCount = shapes.getCount();
shapes.load("items");
await context.sync();
let maxHeight = 0;
shapes.items.map((shape) => {
shape.load("width,height");
});
await context.sync();
shapes.items.map((shape) => {
shape.left = currentLeft;
shape.top = currentTop;
currentLeft += shape.width;
if (shape.height > maxHeight) maxHeight = shape.height;
});
await context.sync();
currentLeft = 0;
if (currentTop > slideHeight - 200) currentTop = 0;
});
Details zur Methode
delete()
Löscht die Form aus der Formsammlung. Tut nichts, wenn das Shape nicht vorhanden ist.
delete(): void;
Gibt zurück
void
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/shapes.yaml
// This function gets the collection of shapes on the first slide,
// and then iterates through them, deleting each one.
await PowerPoint.run(async (context) => {
const slide: PowerPoint.Slide = context.presentation.slides.getItemAt(0);
const shapes: PowerPoint.ShapeCollection = slide.shapes;
// Load all the shapes in the collection without loading their properties.
shapes.load("items/$none");
await context.sync();
shapes.items.forEach((shape) => shape.delete());
await context.sync();
});
getParentSlide()
Gibt das übergeordnete PowerPoint.Slide-Objekt zurück, das dies Shapeenthält. Löst eine Ausnahme aus, wenn dieses Shape nicht zu einer Slidegehört.
getParentSlide(): PowerPoint.Slide;
Gibt zurück
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/text/get-set-textrange.yaml
// Gets navigational (complex) properties of the selected text range.
await PowerPoint.run(async (context) => {
const textRange: PowerPoint.TextRange = context.presentation.getSelectedTextRange();
textRange.load("font,paragraphFormat/bulletFormat,paragraphFormat/horizontalAlignment");
const parentTextFrame: PowerPoint.TextFrame = textRange.getParentTextFrame();
const parentShape: PowerPoint.Shape = parentTextFrame.getParentShape();
const parentSlide: PowerPoint.Slide = parentShape.getParentSlide();
parentShape.load("id");
parentSlide.load("id");
await context.sync();
console.log(`Selected text range found in parent shape with ID ${parentShape.id} on parentSlide with ID ${parentSlide.id}`);
console.log("Font properties of selected text range:");
console.log(`\tallCaps: ${textRange.font.allCaps}`);
console.log(`\tbold: ${textRange.font.bold}`);
console.log(`\tcolor: ${textRange.font.color}`);
console.log(`\tdoubleStrikethrough: ${textRange.font.doubleStrikethrough}`);
console.log(`\titalic: ${textRange.font.italic}`);
console.log(`\tname: ${textRange.font.name}`);
console.log(`\tsize: ${textRange.font.size}`);
console.log(`\tsmallCaps: ${textRange.font.smallCaps}`);
console.log(`\tstrikethrough: ${textRange.font.strikethrough}`);
console.log(`\tsubscript: ${textRange.font.subscript}`);
console.log(`\tsuperscript: ${textRange.font.superscript}`);
console.log(`\tunderline: ${textRange.font.underline}`);
console.log("Paragraph format properties of selected text range:");
console.log(`\tbulletFormat.visible: ${textRange.paragraphFormat.bulletFormat.visible}`);
console.log(`\thorizontalAlignment: ${textRange.paragraphFormat.horizontalAlignment}`);
});
getParentSlideLayout()
Gibt das übergeordnete PowerPoint.SlideLayout-Objekt zurück, das dies Shapeenthält. Löst eine Ausnahme aus, wenn dieses Shape nicht zu einer SlideLayoutgehört.
getParentSlideLayout(): PowerPoint.SlideLayout;
Gibt zurück
Hinweise
getParentSlideLayoutOrNullObject()
Gibt das übergeordnete PowerPoint.SlideLayout-Objekt zurück, das dies Shapeenthält. Wenn diese Form nicht zu einem SlideLayoutgehört, wird ein Objekt mit einer Eigenschaft zurückgegeben, auf die festgelegt isNullObject ist true . Weitere Informationen finden Sie unter *OrNullObject-Methoden und -Eigenschaften.
getParentSlideLayoutOrNullObject(): PowerPoint.SlideLayout;
Gibt zurück
Hinweise
getParentSlideMaster()
Gibt das übergeordnete PowerPoint.SlideMaster-Objekt zurück, das dies Shapeenthält. Löst eine Ausnahme aus, wenn dieses Shape nicht zu einer SlideMastergehört.
getParentSlideMaster(): PowerPoint.SlideMaster;
Gibt zurück
Hinweise
getParentSlideMasterOrNullObject()
Gibt das übergeordnete PowerPoint.SlideMaster-Objekt zurück, das dies Shapeenthält. Wenn diese Form nicht zu einem SlideMastergehört, wird ein Objekt mit einer Eigenschaft zurückgegeben, auf die festgelegt isNullObject ist true . Weitere Informationen finden Sie unter *OrNullObject-Methoden und -Eigenschaften.
getParentSlideMasterOrNullObject(): PowerPoint.SlideMaster;
Gibt zurück
Hinweise
getParentSlideOrNullObject()
Gibt das übergeordnete PowerPoint.Slide-Objekt zurück, das dies Shapeenthält. Wenn diese Form nicht zu einem Slidegehört, wird ein Objekt mit einer Eigenschaft zurückgegeben, auf die festgelegt isNullObject ist true . Weitere Informationen finden Sie unter *OrNullObject-Methoden und -Eigenschaften.
getParentSlideOrNullObject(): PowerPoint.Slide;
Gibt zurück
Hinweise
load(options)
Stellt einen Befehl zum Laden der angegebenen Eigenschaften des Objekts in die Warteschlange ein. Vor dem Lesen der Eigenschaften müssen Sie "context.sync()" aufrufen.
load(options?: PowerPoint.Interfaces.ShapeLoadOptions): PowerPoint.Shape;
Parameter
Stellt Optionen für die zu ladenden Eigenschaften des Objekts bereit.
Gibt zurück
load(propertyNames)
Stellt einen Befehl zum Laden der angegebenen Eigenschaften des Objekts in die Warteschlange ein. Vor dem Lesen der Eigenschaften müssen Sie "context.sync()" aufrufen.
load(propertyNames?: string | string[]): PowerPoint.Shape;
Parameter
- propertyNames
-
string | string[]
Eine durch Trennzeichen getrennte Zeichenfolge oder ein Array von Zeichenfolgen, die die zu ladenden Eigenschaften angeben.
Gibt zurück
load(propertyNamesAndPaths)
Stellt einen Befehl zum Laden der angegebenen Eigenschaften des Objekts in die Warteschlange ein. Vor dem Lesen der Eigenschaften müssen Sie "context.sync()" aufrufen.
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): PowerPoint.Shape;
Parameter
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select ist eine durch Kommas getrennte Zeichenfolge, die die zu ladenden Eigenschaften angibt, und propertyNamesAndPaths.expand eine durch Kommas getrennte Zeichenfolge, die die zu ladenden Navigationseigenschaften angibt.
Gibt zurück
toJSON()
Überschreibt die JavaScript-Methode toJSON() , um eine nützlichere Ausgabe bereitzustellen, wenn ein API-Objekt an JSON.stringify()übergeben wird. (JSON.stringifyruft wiederum die toJSON Methode des Objekts auf, das an sie übergeben wird.) Während das ursprüngliche PowerPoint.Shape Objekt ein API-Objekt ist, gibt die toJSON Methode ein einfaches JavaScript-Objekt (als PowerPoint.Interfaces.ShapeData) zurück, das flache Kopien aller geladenen untergeordneten Eigenschaften des ursprünglichen Objekts enthält.
toJSON(): PowerPoint.Interfaces.ShapeData;