Compartir a través de


PowerPoint.Shape class

Representa una sola forma en la diapositiva.

Extends

Comentarios

[ Conjunto de API: PowerPointApi 1.3 ]

Ejemplos

// 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();
});

Propiedades

context

Contexto de solicitud asociado al objeto . Esto conecta el proceso del complemento al proceso de la aplicación host de Office.

customXmlParts

Devuelve una colección de elementos XML personalizados de la forma.

fill

Devuelve el formato de relleno de esta forma.

group

Devuelve el ShapeGroup objeto asociado a la forma. Si el tipo de forma no groupes , este método devuelve el GeneralException error.

height

Especifica el alto, en puntos, de la forma. Produce una InvalidArgument excepción cuando se establece con un valor negativo.

id

Obtiene el identificador único de la forma.

left

Distancia, en puntos, desde el lado izquierdo de la forma hasta el lado izquierdo de la diapositiva.

level

Devuelve el nivel de la forma especificada.

  • Un nivel de 0 significa que la forma no forma parte de un grupo.

  • Un nivel de 1 significa que la forma forma parte de un grupo de nivel superior.

  • Un nivel mayor que 1 indica que la forma es un grupo anidado.

lineFormat

Devuelve el formato de línea de esta forma.

name

Especifica el nombre de esta forma.

parentGroup

Devuelve el grupo primario de esta forma. Si la forma no forma parte de un grupo, este método devuelve el GeneralException error.

placeholderFormat

Devuelve las propiedades que se aplican específicamente a este marcador de posición. Si el tipo de forma no placeholderes , este método devuelve el GeneralException error.

tags

Devuelve una colección de etiquetas de la forma.

textFrame

Devuelve el objeto PowerPoint.TextFrame de este Shapeobjeto . Produce una InvalidArgument excepción si la forma no admite .TextFrame

top

Distancia, en puntos, desde el borde superior de la forma hasta el borde superior de la diapositiva.

type

Devuelve el tipo de esta forma. Vea PowerPoint.ShapeType para obtener más información.

width

Especifica el ancho, en puntos, de la forma. Produce una InvalidArgument excepción cuando se establece con un valor negativo.

zOrderPosition

Devuelve la posición de orden Z de la forma, con 0 que representa la parte inferior de la pila de pedidos. Cada forma de una diapositiva tiene un orden Z único, pero cada diapositiva también tiene una pila de orden Z única, por lo que dos formas en diapositivas independientes podrían tener el mismo número de orden Z.

Métodos

delete()

Elimina la forma de la colección de formas. No hace nada si la forma no existe.

getParentSlide()

Devuelve el objeto PowerPoint.Slide primario que contiene este Shapeobjeto . Produce una excepción si esta forma no pertenece a .Slide

getParentSlideLayout()

Devuelve el objeto PowerPoint.SlideLayout primario que contiene este Shapeobjeto . Produce una excepción si esta forma no pertenece a .SlideLayout

getParentSlideLayoutOrNullObject()

Devuelve el objeto PowerPoint.SlideLayout primario que contiene este Shapeobjeto . Si esta forma no pertenece a , se devuelve un SlideLayoutobjeto con una isNullObject propiedad establecida en true . Para obtener más información, vea *OrNullObject methods and properties( Métodos y propiedades de *OrNullObject).

getParentSlideMaster()

Devuelve el objeto PowerPoint.SlideMaster primario que contiene este Shapeobjeto . Produce una excepción si esta forma no pertenece a .SlideMaster

getParentSlideMasterOrNullObject()

Devuelve el objeto PowerPoint.SlideMaster primario que contiene este Shapeobjeto . Si esta forma no pertenece a , se devuelve un SlideMasterobjeto con una isNullObject propiedad establecida en true . Para obtener más información, vea *OrNullObject methods and properties( Métodos y propiedades de *OrNullObject).

getParentSlideOrNullObject()

Devuelve el objeto PowerPoint.Slide primario que contiene este Shapeobjeto . Si esta forma no pertenece a , se devuelve un Slideobjeto con una isNullObject propiedad establecida en true . Para obtener más información, vea *OrNullObject methods and properties( Métodos y propiedades de *OrNullObject).

getTable()

Devuelve el Table objeto si esta forma es una tabla.

load(options)

Pone en cola un comando para cargar las propiedades especificadas del objeto. Debe llamar a context.sync() antes de leer las propiedades.

load(propertyNames)

Pone en cola un comando para cargar las propiedades especificadas del objeto. Debe llamar a context.sync() antes de leer las propiedades.

load(propertyNamesAndPaths)

Pone en cola un comando para cargar las propiedades especificadas del objeto. Debe llamar a context.sync() antes de leer las propiedades.

setZOrder(position)

Mueve la forma especificada hacia arriba o hacia abajo en el orden z de la colección, que se desplaza delante o detrás de otras formas.

setZOrder(position)

Mueve la forma especificada hacia arriba o hacia abajo en el orden z de la colección, que se desplaza delante o detrás de otras formas.

toJSON()

Invalida el método JavaScript toJSON() para proporcionar una salida más útil cuando se pasa un objeto de API a JSON.stringify(). (JSON.stringifya su vez, llama al toJSON método del objeto que se le pasa). Mientras que el objeto original PowerPoint.Shape es un objeto de API, el toJSON método devuelve un objeto JavaScript sin formato (escrito como PowerPoint.Interfaces.ShapeData) que contiene copias superficiales de las propiedades secundarias cargadas del objeto original.

Detalles de las propiedades

context

Contexto de solicitud asociado al objeto . Esto conecta el proceso del complemento al proceso de la aplicación host de Office.

context: RequestContext;

Valor de propiedad

customXmlParts

Devuelve una colección de elementos XML personalizados de la forma.

readonly customXmlParts: PowerPoint.CustomXmlPartCollection;

Valor de propiedad

Comentarios

[ Conjunto de API: PowerPointApi 1.7 ]

fill

Devuelve el formato de relleno de esta forma.

readonly fill: PowerPoint.ShapeFill;

Valor de propiedad

Comentarios

[ Conjunto de API: PowerPointApi 1.4 ]

Ejemplos

// 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

Devuelve el ShapeGroup objeto asociado a la forma. Si el tipo de forma no groupes , este método devuelve el GeneralException error.

readonly group: PowerPoint.ShapeGroup;

Valor de propiedad

Comentarios

[ Conjunto de API: PowerPointApi 1.8 ]

Ejemplos

// 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

Especifica el alto, en puntos, de la forma. Produce una InvalidArgument excepción cuando se establece con un valor negativo.

height: number;

Valor de propiedad

number

Comentarios

[ Conjunto de API: PowerPointApi 1.4 ]

Ejemplos

// 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

Obtiene el identificador único de la forma.

readonly id: string;

Valor de propiedad

string

Comentarios

[ Conjunto de API: PowerPointApi 1.3 ]

left

Distancia, en puntos, desde el lado izquierdo de la forma hasta el lado izquierdo de la diapositiva.

left: number;

Valor de propiedad

number

Comentarios

[ Conjunto de API: PowerPointApi 1.4 ]

Ejemplos

// 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

Devuelve el nivel de la forma especificada.

  • Un nivel de 0 significa que la forma no forma parte de un grupo.

  • Un nivel de 1 significa que la forma forma parte de un grupo de nivel superior.

  • Un nivel mayor que 1 indica que la forma es un grupo anidado.

readonly level: number;

Valor de propiedad

number

Comentarios

[ Conjunto de API: PowerPointApi 1.8 ]

lineFormat

Devuelve el formato de línea de esta forma.

readonly lineFormat: PowerPoint.ShapeLineFormat;

Valor de propiedad

Comentarios

[ Conjunto de API: PowerPointApi 1.4 ]

name

Especifica el nombre de esta forma.

name: string;

Valor de propiedad

string

Comentarios

[ Conjunto de API: PowerPointApi 1.4 ]

parentGroup

Devuelve el grupo primario de esta forma. Si la forma no forma parte de un grupo, este método devuelve el GeneralException error.

readonly parentGroup: PowerPoint.Shape;

Valor de propiedad

Comentarios

[ Conjunto de API: PowerPointApi 1.8 ]

placeholderFormat

Devuelve las propiedades que se aplican específicamente a este marcador de posición. Si el tipo de forma no placeholderes , este método devuelve el GeneralException error.

readonly placeholderFormat: PowerPoint.PlaceholderFormat;

Valor de propiedad

Comentarios

[ Conjunto de API: PowerPointApi 1.8 ]

Ejemplos

// 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

Devuelve una colección de etiquetas de la forma.

readonly tags: PowerPoint.TagCollection;

Valor de propiedad

Comentarios

[ Conjunto de API: PowerPointApi 1.3 ]

textFrame

Devuelve el objeto PowerPoint.TextFrame de este Shapeobjeto . Produce una InvalidArgument excepción si la forma no admite .TextFrame

readonly textFrame: PowerPoint.TextFrame;

Valor de propiedad

Comentarios

[ Conjunto de API: PowerPointApi 1.4 ]

top

Distancia, en puntos, desde el borde superior de la forma hasta el borde superior de la diapositiva.

top: number;

Valor de propiedad

number

Comentarios

[ Conjunto de API: PowerPointApi 1.4 ]

Ejemplos

// 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

Devuelve el tipo de esta forma. Vea PowerPoint.ShapeType para obtener más información.

readonly type: PowerPoint.ShapeType | "Unsupported" | "Image" | "GeometricShape" | "Group" | "Line" | "Table" | "Callout" | "Chart" | "ContentApp" | "Diagram" | "Freeform" | "Graphic" | "Ink" | "Media" | "Model3D" | "Ole" | "Placeholder" | "SmartArt" | "TextBox";

Valor de propiedad

PowerPoint.ShapeType | "Unsupported" | "Image" | "GeometricShape" | "Group" | "Line" | "Table" | "Callout" | "Chart" | "ContentApp" | "Diagram" | "Freeform" | "Graphic" | "Ink" | "Media" | "Model3D" | "Ole" | "Placeholder" | "SmartArt" | "TextBox"

Comentarios

[ Conjunto de API: PowerPointApi 1.4 ]

Ejemplos

// 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

Especifica el ancho, en puntos, de la forma. Produce una InvalidArgument excepción cuando se establece con un valor negativo.

width: number;

Valor de propiedad

number

Comentarios

[ Conjunto de API: PowerPointApi 1.4 ]

Ejemplos

// 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

Devuelve la posición de orden Z de la forma, con 0 que representa la parte inferior de la pila de pedidos. Cada forma de una diapositiva tiene un orden Z único, pero cada diapositiva también tiene una pila de orden Z única, por lo que dos formas en diapositivas independientes podrían tener el mismo número de orden Z.

readonly zOrderPosition: number;

Valor de propiedad

number

Comentarios

[ Conjunto de API: PowerPointApi 1.8 ]

Ejemplos

// 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();
    }
  });
}

Detalles del método

delete()

Elimina la forma de la colección de formas. No hace nada si la forma no existe.

delete(): void;

Devoluciones

void

Comentarios

[ Conjunto de API: PowerPointApi 1.3 ]

Ejemplos

// 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()

Devuelve el objeto PowerPoint.Slide primario que contiene este Shapeobjeto . Produce una excepción si esta forma no pertenece a .Slide

getParentSlide(): PowerPoint.Slide;

Devoluciones

Comentarios

[ Conjunto de API: PowerPointApi 1.5 ]

getParentSlideLayout()

Devuelve el objeto PowerPoint.SlideLayout primario que contiene este Shapeobjeto . Produce una excepción si esta forma no pertenece a .SlideLayout

getParentSlideLayout(): PowerPoint.SlideLayout;

Devoluciones

Comentarios

[ Conjunto de API: PowerPointApi 1.5 ]

getParentSlideLayoutOrNullObject()

Devuelve el objeto PowerPoint.SlideLayout primario que contiene este Shapeobjeto . Si esta forma no pertenece a , se devuelve un SlideLayoutobjeto con una isNullObject propiedad establecida en true . Para obtener más información, vea *OrNullObject methods and properties( Métodos y propiedades de *OrNullObject).

getParentSlideLayoutOrNullObject(): PowerPoint.SlideLayout;

Devoluciones

Comentarios

[ Conjunto de API: PowerPointApi 1.5 ]

getParentSlideMaster()

Devuelve el objeto PowerPoint.SlideMaster primario que contiene este Shapeobjeto . Produce una excepción si esta forma no pertenece a .SlideMaster

getParentSlideMaster(): PowerPoint.SlideMaster;

Devoluciones

Comentarios

[ Conjunto de API: PowerPointApi 1.5 ]

getParentSlideMasterOrNullObject()

Devuelve el objeto PowerPoint.SlideMaster primario que contiene este Shapeobjeto . Si esta forma no pertenece a , se devuelve un SlideMasterobjeto con una isNullObject propiedad establecida en true . Para obtener más información, vea *OrNullObject methods and properties( Métodos y propiedades de *OrNullObject).

getParentSlideMasterOrNullObject(): PowerPoint.SlideMaster;

Devoluciones

Comentarios

[ Conjunto de API: PowerPointApi 1.5 ]

getParentSlideOrNullObject()

Devuelve el objeto PowerPoint.Slide primario que contiene este Shapeobjeto . Si esta forma no pertenece a , se devuelve un Slideobjeto con una isNullObject propiedad establecida en true . Para obtener más información, vea *OrNullObject methods and properties( Métodos y propiedades de *OrNullObject).

getParentSlideOrNullObject(): PowerPoint.Slide;

Devoluciones

Comentarios

[ Conjunto de API: PowerPointApi 1.5 ]

getTable()

Devuelve el Table objeto si esta forma es una tabla.

getTable(): PowerPoint.Table;

Devoluciones

Comentarios

[ Conjunto de API: PowerPointApi 1.8 ]

Ejemplos

// 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)

Pone en cola un comando para cargar las propiedades especificadas del objeto. Debe llamar a context.sync() antes de leer las propiedades.

load(options?: PowerPoint.Interfaces.ShapeLoadOptions): PowerPoint.Shape;

Parámetros

options
PowerPoint.Interfaces.ShapeLoadOptions

Proporciona opciones para las propiedades del objeto que se van a cargar.

Devoluciones

load(propertyNames)

Pone en cola un comando para cargar las propiedades especificadas del objeto. Debe llamar a context.sync() antes de leer las propiedades.

load(propertyNames?: string | string[]): PowerPoint.Shape;

Parámetros

propertyNames

string | string[]

Una cadena delimitada por comas o una matriz de cadenas que especifican las propiedades que se van a cargar.

Devoluciones

load(propertyNamesAndPaths)

Pone en cola un comando para cargar las propiedades especificadas del objeto. Debe llamar a context.sync() antes de leer las propiedades.

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): PowerPoint.Shape;

Parámetros

propertyNamesAndPaths

{ select?: string; expand?: string; }

propertyNamesAndPaths.select es una cadena delimitada por comas que especifica las propiedades que se van a cargar y propertyNamesAndPaths.expand es una cadena delimitada por comas que especifica las propiedades de navegación que se van a cargar.

Devoluciones

setZOrder(position)

Mueve la forma especificada hacia arriba o hacia abajo en el orden z de la colección, que se desplaza delante o detrás de otras formas.

setZOrder(position: PowerPoint.ShapeZOrder): void;

Parámetros

position
PowerPoint.ShapeZOrder

Especifica cómo mover la forma dentro de la pila z-order. Usa la ShapeZOrder enumeración .

Devoluciones

void

Comentarios

[ Conjunto de API: PowerPointApi 1.8 ]

Ejemplos

// 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)

Mueve la forma especificada hacia arriba o hacia abajo en el orden z de la colección, que se desplaza delante o detrás de otras formas.

setZOrder(position: "BringForward" | "BringToFront" | "SendBackward" | "SendToBack"): void;

Parámetros

position

"BringForward" | "BringToFront" | "SendBackward" | "SendToBack"

Especifica cómo mover la forma dentro de la pila z-order. Usa la ShapeZOrder enumeración .

Devoluciones

void

Comentarios

[ Conjunto de API: PowerPointApi 1.8 ]

toJSON()

Invalida el método JavaScript toJSON() para proporcionar una salida más útil cuando se pasa un objeto de API a JSON.stringify(). (JSON.stringifya su vez, llama al toJSON método del objeto que se le pasa). Mientras que el objeto original PowerPoint.Shape es un objeto de API, el toJSON método devuelve un objeto JavaScript sin formato (escrito como PowerPoint.Interfaces.ShapeData) que contiene copias superficiales de las propiedades secundarias cargadas del objeto original.

toJSON(): PowerPoint.Interfaces.ShapeData;

Devoluciones