PowerPoint.Shape class
Stellt ein einzelnes Shape auf der Folie dar.
- Extends
Hinweise
Verwendet von
- PowerPoint.Binding: getShape
- PowerPoint.BindingCollection: hinzufügen
- PowerPoint.ShapeCollection: addGeometricShape, addGroup, addLine, addTable, addTextBox, getItem, getItemAt, getItemOrNullObject, Elemente
- 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
| 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. |
| 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. |
| 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 |
| 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 |
| 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 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 |
| 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 |
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
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();
});
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
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}`);
}
});
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;
});
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();
});
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.");
});
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
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;