PowerPoint.Shape class

Representa uma única forma no slide.

Extends

Comentários

Conjunto de APIs: PowerPointApi 1.3

Usada por

Exemplos

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

Propriedades

context

O contexto de solicitação associado ao objeto. Isso conecta o processo do suplemento ao processo do aplicativo host do Office.

fill

Retorna a formatação de preenchimento dessa forma.

height

Especifica a altura, em pontos, da forma. Lança uma InvalidArgument exceção quando definido com um valor negativo.

id

Obtém a ID exclusiva da forma.

left

A distância, em pontos, do lado esquerdo da forma até o lado esquerdo do slide.

lineFormat

Retorna a formatação de linha do objeto de forma.

name

Especifica o nome dessa forma.

tags

Retorna uma coleção de marcas na forma.

textFrame

Retorna o objeto PowerPoint.TextFrame deste Shape. Lançará uma InvalidArgument exceção se a forma não for compatível com um TextFramedomínio .

top

A distância, em pontos, da borda superior da forma até a borda superior do slide.

type

Retorna o tipo dessa forma. Confira PowerPoint.ShapeType para obter detalhes.

width

Especifica a largura, em pontos, da forma. Lança uma InvalidArgument exceção quando definido com um valor negativo.

Métodos

delete()

Exclui a forma da coleção de formas. Não fará nada se a forma não existir.

load(options)

Coloca um comando na fila para carregar as propriedades especificadas do objeto. Você deve chamar context.sync() antes de ler as propriedades.

load(propertyNames)

Coloca um comando na fila para carregar as propriedades especificadas do objeto. Você deve chamar context.sync() antes de ler as propriedades.

load(propertyNamesAndPaths)

Coloca um comando na fila para carregar as propriedades especificadas do objeto. Você deve chamar context.sync() antes de ler as propriedades.

toJSON()

Substitui o método JavaScript toJSON() para fornecer uma saída mais útil quando um objeto de API é passado para JSON.stringify(). (JSON.stringify, por sua vez, chama o toJSON método do objeto que é passado para ele.) Enquanto o objeto original PowerPoint.Shape é um objeto de API, o toJSON método retorna um objeto JavaScript simples (digitado como PowerPoint.Interfaces.ShapeData) que contém cópias superficiais de todas as propriedades filho carregadas do objeto original.

Detalhes da propriedade

context

O contexto de solicitação associado ao objeto. Isso conecta o processo do suplemento ao processo do aplicativo host do Office.

context: RequestContext;

Valor da propriedade

fill

Retorna a formatação de preenchimento dessa forma.

readonly fill: PowerPoint.ShapeFill;

Valor da propriedade

Comentários

Conjunto de APIs: PowerPointApi 1.4

Exemplos

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-set-shapes.yaml

// Changes the selected shapes fill color to red.
await PowerPoint.run(async (context) => {
  const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
  const shapeCount = shapes.getCount();
  shapes.load("items/fill/type");
  await context.sync();
  shapes.items.map((shape) => {
    const shapeFillType = shape.fill.type as PowerPoint.ShapeFillType;
    console.log(`Shape ID ${shape.id} original fill type: ${shapeFillType}`);
    shape.fill.setSolidColor("red");
  });
  await context.sync();
});

height

Especifica a altura, em pontos, da forma. Lança uma InvalidArgument exceção quando definido com um valor negativo.

height: number;

Valor da propriedade

number

Comentários

Conjunto de APIs: PowerPointApi 1.4

Exemplos

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

Obtém a ID exclusiva da forma.

readonly id: string;

Valor da propriedade

string

Comentários

Conjunto de APIs: PowerPointApi 1.3

left

A distância, em pontos, do lado esquerdo da forma até o lado esquerdo do slide.

left: number;

Valor da propriedade

number

Comentários

Conjunto de APIs: PowerPointApi 1.4

Exemplos

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-set-shapes.yaml

// Arranges the selected shapes in a line from left to right.
await PowerPoint.run(async (context) => {
  const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
  const shapeCount = shapes.getCount();
  shapes.load("items");
  await context.sync();
  let maxHeight = 0;
  shapes.items.map((shape) => {
    shape.load("width,height");
  });
  await context.sync();
  shapes.items.map((shape) => {
    shape.left = currentLeft;
    shape.top = currentTop;
    currentLeft += shape.width;
    if (shape.height > maxHeight) maxHeight = shape.height;
  });
  await context.sync();
  currentLeft = 0;
  if (currentTop > slideHeight - 200) currentTop = 0;
});

lineFormat

Retorna a formatação de linha do objeto de forma.

readonly lineFormat: PowerPoint.ShapeLineFormat;

Valor da propriedade

Comentários

Conjunto de APIs: PowerPointApi 1.4

name

Especifica o nome dessa forma.

name: string;

Valor da propriedade

string

Comentários

Conjunto de APIs: PowerPointApi 1.4

tags

Retorna uma coleção de marcas na forma.

readonly tags: PowerPoint.TagCollection;

Valor da propriedade

Comentários

Conjunto de APIs: PowerPointApi 1.3

textFrame

Retorna o objeto PowerPoint.TextFrame deste Shape. Lançará uma InvalidArgument exceção se a forma não for compatível com um TextFramedomínio .

readonly textFrame: PowerPoint.TextFrame;

Valor da propriedade

Comentários

Conjunto de APIs: PowerPointApi 1.4

top

A distância, em pontos, da borda superior da forma até a borda superior do slide.

top: number;

Valor da propriedade

number

Comentários

Conjunto de APIs: PowerPointApi 1.4

Exemplos

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

Retorna o tipo dessa forma. Confira PowerPoint.ShapeType para obter detalhes.

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

Valor da propriedade

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

Comentários

Conjunto de APIs: PowerPointApi 1.4

Exemplos

// 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 a largura, em pontos, da forma. Lança uma InvalidArgument exceção quando definido com um valor negativo.

width: number;

Valor da propriedade

number

Comentários

Conjunto de APIs: PowerPointApi 1.4

Exemplos

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

Detalhes do método

delete()

Exclui a forma da coleção de formas. Não fará nada se a forma não existir.

delete(): void;

Retornos

void

Comentários

Conjunto de APIs: PowerPointApi 1.3

Exemplos

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

load(options)

Coloca um comando na fila para carregar as propriedades especificadas do objeto. Você deve chamar context.sync() antes de ler as propriedades.

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

Parâmetros

options
PowerPoint.Interfaces.ShapeLoadOptions

Fornece opções para quais propriedades do objeto devem ser carregadas.

Retornos

load(propertyNames)

Coloca um comando na fila para carregar as propriedades especificadas do objeto. Você deve chamar context.sync() antes de ler as propriedades.

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

Parâmetros

propertyNames

string | string[]

Uma cadeia de caracteres delimitada por vírgula ou uma matriz de cadeias de caracteres que especifica as propriedades a serem carregadas.

Retornos

load(propertyNamesAndPaths)

Coloca um comando na fila para carregar as propriedades especificadas do objeto. Você deve chamar context.sync() antes de ler as propriedades.

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

Parâmetros

propertyNamesAndPaths

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

propertyNamesAndPaths.select é uma cadeia de caracteres delimitada por vírgula que especifica as propriedades a serem carregadas e propertyNamesAndPaths.expand é uma cadeia de caracteres delimitada por vírgula que especifica as propriedades de navegação a serem carregadas.

Retornos

toJSON()

Substitui o método JavaScript toJSON() para fornecer uma saída mais útil quando um objeto de API é passado para JSON.stringify(). (JSON.stringify, por sua vez, chama o toJSON método do objeto que é passado para ele.) Enquanto o objeto original PowerPoint.Shape é um objeto de API, o toJSON método retorna um objeto JavaScript simples (digitado como PowerPoint.Interfaces.ShapeData) que contém cópias superficiais de todas as propriedades filho carregadas do objeto original.

toJSON(): PowerPoint.Interfaces.ShapeData;

Retornos