PowerPoint.Shape class
Stellt ein einzelnes Shape auf der Folie dar.
- Extends
Hinweise
Verwendet von
- PowerPoint.Binding: getShape
- PowerPoint.BindingCollection: hinzufügen
- PowerPoint.Graphic: Form
- PowerPoint.Hyperlink: getLinkedShapeOrNullObject
- PowerPoint.HyperlinkCollection: hinzufügen
- PowerPoint.ShapeCollection: addGeometricShape, addGroup, addLine, addPicture, addTable, addTextBox, getItem, getItemAt, getItemOrNullObject, items
- PowerPoint.ShapeGroup: Form
- PowerPoint.ShapeScopedCollection: getItem, getItemAt, getItemOrNullObject, Gruppe, Elemente
- PowerPoint.Table: getShape
- 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
| adjustments | Gibt ein |
| alt |
Die Alternativtextbeschreibung der Form. Alternativtext stellt alternative, textbasierte Darstellungen der im Shape enthaltenen Informationen bereit. Diese Informationen sind nützlich für Personen mit Sehkraft oder kognitiven Beeinträchtigungen, die die Form möglicherweise nicht sehen oder verstehen können. |
| alt |
Der Alternativtexttitel des Shapes. Alternativtext stellt alternative, textbasierte Darstellungen der im Shape enthaltenen Informationen bereit. Diese Informationen sind nützlich für Personen mit Sehkraft oder kognitiven Beeinträchtigungen, die die Form möglicherweise nicht sehen oder verstehen können. Ein Titel kann einer Person mit einer Behinderung vorgelesen werden und wird verwendet, um festzustellen, ob sie die Beschreibung des Inhalts hören möchte. |
| context | Der dem Objekt zugeordnete Anforderungskontext. Dadurch wird der Prozess des Add-Ins mit dem Prozess der Office-Hostanwendung verbunden. |
| creation |
Ruft die Erstellungs-ID der Form ab. Gibt zurück |
| custom |
Gibt eine Auflistung benutzerdefinierter XML-Teile in der Form zurück. |
| fill | Gibt die Füllungsformatierung dieser Form zurück. |
| group | Gibt das der Form zugeordnete Element |
| height | Gibt die Höhe des Shapes in Punkten an. Löst eine |
| id | Ruft die eindeutige ID des Shapes ab. |
| is |
Stellt dar, ob die Form dekorativ ist oder nicht. Dekorative Objekte machen etwas visuell interessanter, sind aber nicht informativ (z. B. dekorative Rahmen). People, die Sprachausgaben verwenden, können hören, dass diese Objekte dekorativ sind, und wissen dann, dass ihnen keine wichtigen Informationen entgehen. |
| left | Der Abstand in Punkten von der linken Seite des Shapes zur linken Seite der Folie. |
| level | Gibt die Höhe der angegebenen Form zurück.
|
| line |
Gibt die Linienformatierung dieser Form zurück. |
| name | Gibt den Namen dieses Shapes an. |
| parent |
Gibt die übergeordnete Gruppe dieses Shapes zurück. Wenn das Shape nicht Teil einer Gruppe ist, wird der |
| placeholder |
Gibt die Eigenschaften zurück, die speziell für diesen Platzhalter gelten. Wenn der Formtyp nicht |
| rotation | Gibt die Drehung des Shapes um die Z-Achse in Grad an. Ein positiver Wert zeigt eine Drehung im Uhrzeigersinn und ein negativer Wert eine Drehung gegen den Uhrzeigersinn 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 . |
| visible | Gibt an, ob das Shape sichtbar ist. |
| width | Gibt die Breite des Shapes in Punkten an. Löst eine |
| z |
Gibt die Z-Reihenfolge-Position der Form zurück, wobei 0 den unteren Rand des Ordnungsstapels darstellt. Jedes Shape auf einer Folie hat eine eindeutige Z-Reihenfolge, aber jede Folie hat auch einen eindeutigen Z-Reihenfolge-Stapel, sodass zwei Shapes auf getrennten Folien die gleiche Z-Reihenfolge-Nummer haben können. |
Methoden
| delete() | Löscht die Form aus der Formsammlung. Tut nichts, wenn das Shape nicht vorhanden ist. |
| get |
Gibt ein PowerPoint.Graphic-Objekt zurück, wenn diese Form eine ShapeType.graphic ist. Wenn diese Form kein |
| get |
Rendert ein Bild der Form. |
| 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 |
| get |
Gibt das |
| get |
Gibt das PowerPoint.TextFrame-Objekt dieses |
| 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 " |
| set |
Legt hierzu |
| set |
Verschiebt de angegebene Form in der Z-Reihenfolge der Sammlung nach oben oder unten, wodurch sie vor oder hinter anderen Formen zu liegen kommt. |
| set |
Verschiebt de angegebene Form in der Z-Reihenfolge der Sammlung nach oben oder unten, wodurch sie vor oder hinter anderen Formen zu liegen kommt. |
| toJSON() | Überschreibt die JavaScript-Methode |
Details zur Eigenschaft
adjustments
Gibt ein Adjustments Objekt zurück, das Anpassungswerte für alle Anpassungen in diesem Shape enthält.
readonly adjustments: PowerPoint.Adjustments;
Eigenschaftswert
Hinweise
altTextDescription
Die Alternativtextbeschreibung der Form.
Alternativtext stellt alternative, textbasierte Darstellungen der im Shape enthaltenen Informationen bereit. Diese Informationen sind nützlich für Personen mit Sehkraft oder kognitiven Beeinträchtigungen, die die Form möglicherweise nicht sehen oder verstehen können.
altTextDescription: string;
Eigenschaftswert
string
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/preview-apis/add-picture.yaml
// Reads the accessibility properties of the first selected shape.
await PowerPoint.run(async (context) => {
const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
const shapeCount = shapes.getCount();
await context.sync();
if (shapeCount.value === 0) {
console.warn("No shapes are selected. Select a shape on the slide and try again.");
return;
}
const shape: PowerPoint.Shape = shapes.getItemAt(0);
shape.load("id,name,altTextTitle,altTextDescription,isDecorative");
await context.sync();
console.log(`Shape ID: ${shape.id}`);
console.log(`Name: "${shape.name}"`);
console.log(`Alt text title: "${shape.altTextTitle}"`);
console.log(`Alt text description: "${shape.altTextDescription}"`);
console.log(`Is decorative: ${shape.isDecorative}`);
});
altTextTitle
Der Alternativtexttitel des Shapes.
Alternativtext stellt alternative, textbasierte Darstellungen der im Shape enthaltenen Informationen bereit. Diese Informationen sind nützlich für Personen mit Sehkraft oder kognitiven Beeinträchtigungen, die die Form möglicherweise nicht sehen oder verstehen können. Ein Titel kann einer Person mit einer Behinderung vorgelesen werden und wird verwendet, um festzustellen, ob sie die Beschreibung des Inhalts hören möchte.
altTextTitle: string;
Eigenschaftswert
string
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/preview-apis/add-picture.yaml
// Insert a picture on the current slide.
await PowerPoint.run(async (context) => {
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
// Use PictureAddOptions to control the position and dimensions (in points).
const options: PowerPoint.PictureAddOptions = {
left: 100,
top: 100,
width: 250,
height: 180,
};
const picture: PowerPoint.Shape = slide.shapes.addPicture(getSampleImageBase64(), options);
picture.name = "SamplePicture";
// Set accessibility properties on the inserted picture.
picture.altTextTitle = "Sample image";
picture.altTextDescription = "A cartoon dog image used as a sample picture in this add-in.";
await context.sync();
});
context
Der dem Objekt zugeordnete Anforderungskontext. Dadurch wird der Prozess des Add-Ins mit dem Prozess der Office-Hostanwendung verbunden.
context: RequestContext;
Eigenschaftswert
creationId
Ruft die Erstellungs-ID der Form ab. Gibt zurück null , wenn das Shape keine Erstellungs-ID hat.
readonly creationId: string | null;
Eigenschaftswert
string | null
Hinweise
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();
});
group
Gibt das der Form zugeordnete Element ShapeGroup zurück. Wenn der Formtyp nicht groupangegeben ist, wird der Fehler bei dieser GeneralException Methode zurückgegeben.
readonly group: PowerPoint.ShapeGroup;
Eigenschaftswert
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/group-ungroup-shapes.yaml
await PowerPoint.run(async (context) => {
// Ungroups the first shape group on the current slide.
// Get the shapes on the current slide.
context.presentation.load("slides");
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
slide.load("shapes/items/type,shapes/items/id");
await context.sync();
const shapes: PowerPoint.ShapeCollection = slide.shapes;
const shapeGroups = shapes.items.filter((item) => item.type === PowerPoint.ShapeType.group);
if (shapeGroups.length === 0) {
console.warn("No shape groups on the current slide, so nothing to ungroup.");
return;
}
// Ungroup the first grouped shapes.
const firstGroupId = shapeGroups[0].id;
const shapeGroupToUngroup = shapes.getItem(firstGroupId);
shapeGroupToUngroup.group.ungroup();
await context.sync();
console.log(`Ungrouped shapes with group ID: ${firstGroupId}`);
});
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
isDecorative
Stellt dar, ob die Form dekorativ ist oder nicht.
Dekorative Objekte machen etwas visuell interessanter, sind aber nicht informativ (z. B. dekorative Rahmen). People, die Sprachausgaben verwenden, können hören, dass diese Objekte dekorativ sind, und wissen dann, dass ihnen keine wichtigen Informationen entgehen.
isDecorative: boolean;
Eigenschaftswert
boolean
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/preview-apis/add-picture.yaml
// Toggles the isDecorative property on the first selected shape.
// When isDecorative is true, screen readers announce the shape as
// decorative, indicating no alt text is needed.
await PowerPoint.run(async (context) => {
const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
const shapeCount = shapes.getCount();
await context.sync();
if (shapeCount.value === 0) {
console.warn("No shapes are selected. Select a shape on the slide and try again.");
return;
}
const shape: PowerPoint.Shape = shapes.getItemAt(0);
shape.load("name,isDecorative");
await context.sync();
const wasDecorative = shape.isDecorative;
shape.isDecorative = !wasDecorative;
await context.sync();
console.log(`Shape "${shape.name}" isDecorative changed: ${wasDecorative} → ${shape.isDecorative}`);
});
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;
});
level
Gibt die Höhe der angegebenen Form zurück.
Der Wert 0 bedeutet, dass die Form nicht Teil einer Gruppe ist.
Eine Ebene von 1 bedeutet, dass das Shape Teil einer Gruppe der obersten Ebene ist.
Eine Ebene größer als 1 gibt an, dass das Shape eine geschachtelte Gruppe ist.
readonly level: number;
Eigenschaftswert
number
Hinweise
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
parentGroup
Gibt die übergeordnete Gruppe dieses Shapes zurück. Wenn das Shape nicht Teil einer Gruppe ist, wird der GeneralException Fehler mithilfe dieser Methode zurückgegeben.
readonly parentGroup: PowerPoint.Shape;
Eigenschaftswert
Hinweise
placeholderFormat
Gibt die Eigenschaften zurück, die speziell für diesen Platzhalter gelten. Wenn der Formtyp nicht placeholderangegeben ist, wird der Fehler bei dieser GeneralException Methode zurückgegeben.
readonly placeholderFormat: PowerPoint.PlaceholderFormat;
Eigenschaftswert
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-shapes-by-type.yaml
// Gets the placeholder shapes in the slide.
await PowerPoint.run(async (context) => {
// Get properties for every shape in the collection.
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
shapes.load("type,name");
await context.sync();
const placeholderShapes = [];
console.log(`Number of shapes found: ${shapes.items.length}`);
shapes.items.forEach((shape) => {
if (shape.type === PowerPoint.ShapeType.placeholder) {
// Load placeholderFormat property.
// PowerPoint throws an exception if you try to load this property on a shape that isn't a placeholder type.
shape.load("placeholderFormat");
placeholderShapes.push(shape);
}
});
await context.sync();
console.log(`Number of placeholder shapes found: ${placeholderShapes.length}`);
for (let i = 0; i < placeholderShapes.length; i++) {
let currentPlaceholder: PowerPoint.PlaceholderFormat = placeholderShapes[i].placeholderFormat;
let placeholderType = currentPlaceholder.type as PowerPoint.PlaceholderType;
let placeholderContainedType = currentPlaceholder.containedType as PowerPoint.ShapeType;
console.log(`Shape "${placeholderShapes[i].name}" placeholder properties:`);
console.log(`\ttype: ${placeholderType}`);
console.log(`\tcontainedType: ${placeholderContainedType}`);
}
});
rotation
Gibt die Drehung des Shapes um die Z-Achse in Grad an. Ein positiver Wert zeigt eine Drehung im Uhrzeigersinn und ein negativer Wert eine Drehung gegen den Uhrzeigersinn an.
rotation: number;
Eigenschaftswert
number
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();
});
visible
Gibt an, ob das Shape sichtbar ist.
visible: boolean;
Eigenschaftswert
boolean
Hinweise
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;
});
zOrderPosition
Gibt die Z-Reihenfolge-Position der Form zurück, wobei 0 den unteren Rand des Ordnungsstapels darstellt. Jedes Shape auf einer Folie hat eine eindeutige Z-Reihenfolge, aber jede Folie hat auch einen eindeutigen Z-Reihenfolge-Stapel, sodass zwei Shapes auf getrennten Folien die gleiche Z-Reihenfolge-Nummer haben können.
readonly zOrderPosition: number;
Eigenschaftswert
number
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/binding-to-shapes.yaml
async function changeZOrder(operation: PowerPoint.ShapeZOrder) {
// Changes the z-order position of the selected shapes.
return PowerPoint.run(async (context) => {
const selectedShapes = context.presentation.getSelectedShapes();
selectedShapes.load();
await context.sync();
if (selectedShapes.items.length === 0) {
console.log("No shapes are selected.");
} else {
let direction = 1; // Start with bottom-most (lowest number).
// Start with top-most when sending to back or bringing forward.
switch (operation) {
case PowerPoint.ShapeZOrder.bringForward:
case PowerPoint.ShapeZOrder.sendToBack:
direction = -1; // Reverse direction.
break;
}
// Change the z-order position for each of the selected shapes,
// starting with the bottom-most when bringing to front or sending backward,
// or top-most when sending to back or bringing forward,
// so the selected shapes retain their relative z-order positions after they're changed.
selectedShapes.items
.sort((a, b) => (a.zOrderPosition - b.zOrderPosition) * direction)
.forEach((shape) => {
try {
const originalZOrderPosition = shape.zOrderPosition;
shape.setZOrder(operation);
console.log(`Changed z-order of shape ${shape.id}.`);
} catch (err) {
console.log(`Unable to change z-order of shape ${shape.id}. ${err.message}`);
}
});
await context.sync();
}
});
}
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();
});
getGraphicOrNullObject()
Hinweis
Diese API wird als Vorschau für Entwickler bereitgestellt. Je nachdem, welches Feedback wir dazu erhalten, werden möglicherweise Änderungen vorgenommen. Verwenden Sie diese API nicht in einer Produktionsumgebung.
Gibt ein PowerPoint.Graphic-Objekt zurück, wenn diese Form eine ShapeType.graphic ist. Wenn diese Form kein Graphicist, wird ein Objekt mit einer Eigenschaft zurückgegeben, auf die festgelegt isNullObject ist true . Weitere Informationen finden Sie unter *OrNullObject-Methoden und -Eigenschaften.
getGraphicOrNullObject(): PowerPoint.Graphic;
Gibt zurück
Hinweise
getImageAsBase64(options)
Rendert ein Bild der Form.
getImageAsBase64(options?: PowerPoint.ShapeGetImageOptions): OfficeExtension.ClientResult<string>;
Parameter
- options
- PowerPoint.ShapeGetImageOptions
Optional. Optionen zum Festlegen der gewünschten Ausgabebildeigenschaften.
Gibt zurück
OfficeExtension.ClientResult<string>
Eine Base64-codierte Zeichenfolge des Formbilds im angegebenen Format.
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-shape-as-image.yaml
// Gets an image of the first selected shape using default options
// (PNG format at the shape's original size).
await PowerPoint.run(async (context) => {
const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
const shapeCount = shapes.getCount();
await context.sync();
if (shapeCount.value === 0) {
console.warn("No shapes are selected. Please select a shape and try again.");
return;
}
const shape: PowerPoint.Shape = shapes.getItemAt(0);
// Call getImageAsBase64 with no options - returns PNG at the shape's true size.
const imageResult: OfficeExtension.ClientResult<string> = shape.getImageAsBase64();
await context.sync();
displayImage(imageResult.value, "Default (original size, PNG)");
});
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
getTable()
Gibt das Table Objekt zurück, wenn dieses Shape eine Tabelle ist.
getTable(): PowerPoint.Table;
Gibt zurück
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/add-modify-tables.yaml
// Gets the table from a shape.
await PowerPoint.run(async (context) => {
const shapes = context.presentation.getSelectedShapes();
const shapeCount = shapes.getCount();
shapes.load("items");
await context.sync();
if (shapeCount.value > 0) {
const shape = shapes.getItemAt(0);
shape.load("type");
await context.sync();
// The shape type can indicate whether the shape is a table.
const isTable = shape.type === PowerPoint.ShapeType.table;
if (isTable) {
// Get the Table object for the Shape which is a table.
const table = shape.getTable();
table.load();
await context.sync();
// Get the Table row and column count.
console.log("Table RowCount: " + table.rowCount + " and columnCount: " + table.columnCount);
} else console.log("Selected shape isn't table.");
} else console.log("No shape selected.");
});
getTextFrameOrNullObject()
Gibt das PowerPoint.TextFrame-Objekt dieses Shapezurück. Wenn das Shape ein TextFramenicht unterstützt, wird ein Objekt mit einer isNullObject Eigenschaft zurückgegeben, auf die zugegriffen werden soll true . Weitere Informationen finden Sie unter *OrNullObject-Methoden und -Eigenschaften.
getTextFrameOrNullObject(): PowerPoint.TextFrame;
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
setHyperlink(options)
Legt hierzu Shape einen Link mit den angegebenen Optionen fest. Hiermit werden alle vorhandenen Links auf dieser Shape.
setHyperlink(options?: PowerPoint.HyperlinkAddOptions): PowerPoint.Hyperlink;
Parameter
- options
- PowerPoint.HyperlinkAddOptions
Optional. Die Optionen für den Hyperlink.
Gibt zurück
Das neu erstellte PowerPoint.Hyperlink-Objekt .
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/hyperlinks/manage-hyperlinks.yaml
// Updates the hyperlink on the first selected shape on the current slide.
await PowerPoint.run(async (context) => {
const shape: PowerPoint.Shape = context.presentation.getSelectedShapes().getItemAt(0).load("type");
const hyperlinkAddOptions: PowerPoint.HyperlinkAddOptions = {
address: "https://www.microsoft.com",
screenTip: "Updated screen tip of link on shape",
};
const hyperlink: PowerPoint.Hyperlink = shape.setHyperlink(hyperlinkAddOptions).load("address,screenTip");
try {
await context.sync();
} catch {
console.warn("Confirm that you have at least one slide and you've selected a shape on the active slide.");
return;
}
console.log(
`Updated link on the selected ${shape.type} shape to "${hyperlink.address}" (screen tip: "${hyperlink.screenTip}").`,
);
});
setZOrder(position)
Verschiebt de angegebene Form in der Z-Reihenfolge der Sammlung nach oben oder unten, wodurch sie vor oder hinter anderen Formen zu liegen kommt.
setZOrder(position: PowerPoint.ShapeZOrder): void;
Parameter
- position
- PowerPoint.ShapeZOrder
Gibt an, wie das Shape innerhalb des Stapels in z-Reihenfolge verschoben werden soll. Verwendet die ShapeZOrder Aufzählung.
Gibt zurück
void
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/binding-to-shapes.yaml
async function changeZOrder(operation: PowerPoint.ShapeZOrder) {
// Changes the z-order position of the selected shapes.
return PowerPoint.run(async (context) => {
const selectedShapes = context.presentation.getSelectedShapes();
selectedShapes.load();
await context.sync();
if (selectedShapes.items.length === 0) {
console.log("No shapes are selected.");
} else {
let direction = 1; // Start with bottom-most (lowest number).
// Start with top-most when sending to back or bringing forward.
switch (operation) {
case PowerPoint.ShapeZOrder.bringForward:
case PowerPoint.ShapeZOrder.sendToBack:
direction = -1; // Reverse direction.
break;
}
// Change the z-order position for each of the selected shapes,
// starting with the bottom-most when bringing to front or sending backward,
// or top-most when sending to back or bringing forward,
// so the selected shapes retain their relative z-order positions after they're changed.
selectedShapes.items
.sort((a, b) => (a.zOrderPosition - b.zOrderPosition) * direction)
.forEach((shape) => {
try {
const originalZOrderPosition = shape.zOrderPosition;
shape.setZOrder(operation);
console.log(`Changed z-order of shape ${shape.id}.`);
} catch (err) {
console.log(`Unable to change z-order of shape ${shape.id}. ${err.message}`);
}
});
await context.sync();
}
});
}
setZOrder(position)
Verschiebt de angegebene Form in der Z-Reihenfolge der Sammlung nach oben oder unten, wodurch sie vor oder hinter anderen Formen zu liegen kommt.
setZOrder(position: "BringForward" | "BringToFront" | "SendBackward" | "SendToBack"): void;
Parameter
- position
-
"BringForward" | "BringToFront" | "SendBackward" | "SendToBack"
Gibt an, wie das Shape innerhalb des Stapels in z-Reihenfolge verschoben werden soll. Verwendet die ShapeZOrder Aufzählung.
Gibt zurück
void
Hinweise
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;