PowerPoint.TextRange class

Contém o texto que é anexado a uma forma, bem como propriedades e métodos para manipular o texto.

Extends

Comentários

Conjunto de APIs: PowerPointApi 1.4

Usada por

Exemplos

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

// Sets the color of the selected text range to green.
await PowerPoint.run(async (context) => {
  const textRange: PowerPoint.TextRange = context.presentation.getSelectedTextRange();
  textRange.font.color = "green";
  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.

font

Retorna um ShapeFont objeto que representa os atributos de fonte para o intervalo de texto.

hyperlinks

Retorna uma coleção de hiperlinks que existem neste TextRange.

length

Obtém ou define o comprimento do intervalo que isso TextRange representa. Lança uma InvalidArgument exceção quando definido com um valor negativo ou se o valor é maior do que o comprimento do texto disponível desde o ponto inicial.

paragraphFormat

Representa o formato de parágrafo do intervalo de texto. Confira PowerPoint.ParagraphFormat para obter detalhes.

start

Obtém ou define o índice baseado em zero, relativo ao quadro de texto pai, para a posição inicial do intervalo que isso TextRange representa. Lança uma InvalidArgument exceção quando definido com um valor negativo ou se o valor for maior que o comprimento do texto.

text

Representa o conteúdo de texto sem formatação do intervalo de texto.

Métodos

getParentTextFrame()

Retorna o objeto PowerPoint.TextFrame pai que contém esse TextRangeobjeto .

getSubstring(start, length)

Retorna um TextRange objeto para a subcadeia de caracteres no intervalo especificado.

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.

setHyperlink(options)

Define um hiperlink com TextRange as opções especificadas. Isso excluirá todos os hiperlinks existentes neste TextRange.

setSelected()

Seleciona isso TextRange no modo de exibição atual.

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.TextRange é um objeto de API, o toJSON método retorna um objeto JavaScript simples (digitado como PowerPoint.Interfaces.TextRangeData) 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

font

Retorna um ShapeFont objeto que representa os atributos de fonte para o intervalo de texto.

readonly font: PowerPoint.ShapeFont;

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/text/get-set-textrange.yaml

// Sets the color of the selected text range to green.
await PowerPoint.run(async (context) => {
  const textRange: PowerPoint.TextRange = context.presentation.getSelectedTextRange();
  textRange.font.color = "green";
  await context.sync();
});

Retorna uma coleção de hiperlinks que existem neste TextRange.

readonly hyperlinks: PowerPoint.HyperlinkScopedCollection;

Valor da propriedade

Comentários

Conjunto de APIs: PowerPointApi 1.10

length

Obtém ou define o comprimento do intervalo que isso TextRange representa. Lança uma InvalidArgument exceção quando definido com um valor negativo ou se o valor é maior do que o comprimento do texto disponível desde o ponto inicial.

length: number;

Valor da propriedade

number

Comentários

Conjunto de APIs: PowerPointApi 1.5

paragraphFormat

Representa o formato de parágrafo do intervalo de texto. Confira PowerPoint.ParagraphFormat para obter detalhes.

readonly paragraphFormat: PowerPoint.ParagraphFormat;

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

start

Obtém ou define o índice baseado em zero, relativo ao quadro de texto pai, para a posição inicial do intervalo que isso TextRange representa. Lança uma InvalidArgument exceção quando definido com um valor negativo ou se o valor for maior que o comprimento do texto.

start: number;

Valor da propriedade

number

Comentários

Conjunto de APIs: PowerPointApi 1.5

text

Representa o conteúdo de texto sem formatação do intervalo de texto.

text: string;

Valor da propriedade

string

Comentários

Conjunto de APIs: PowerPointApi 1.4

Detalhes do método

getParentTextFrame()

Retorna o objeto PowerPoint.TextFrame pai que contém esse TextRangeobjeto .

getParentTextFrame(): PowerPoint.TextFrame;

Retornos

Comentários

Conjunto de APIs: PowerPointApi 1.5

Exemplos

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

getSubstring(start, length)

Retorna um TextRange objeto para a subcadeia de caracteres no intervalo especificado.

getSubstring(start: number, length?: number): PowerPoint.TextRange;

Parâmetros

start

number

O índice baseado em zero do primeiro caractere a ser obtido do intervalo de texto.

length

number

Opcional. O número de caracteres a serem retornados no novo intervalo de texto. Se o comprimento for omitido, todos os caracteres do início ao fim do último parágrafo do intervalo de texto serão retornados.

Retornos

Comentários

Conjunto de APIs: PowerPointApi 1.4

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.TextRangeLoadOptions): PowerPoint.TextRange;

Parâmetros

options
PowerPoint.Interfaces.TextRangeLoadOptions

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.TextRange;

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.TextRange;

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

Define um hiperlink com TextRange as opções especificadas. Isso excluirá todos os hiperlinks existentes neste TextRange.

setHyperlink(options?: PowerPoint.HyperlinkAddOptions): PowerPoint.Hyperlink;

Parâmetros

options
PowerPoint.HyperlinkAddOptions

Opcional. As opções para o hiperlink.

Retornos

O objeto PowerPoint.Hyperlink recém-criado.

Comentários

Conjunto de APIs: PowerPointApi 1.10

setSelected()

Seleciona isso TextRange no modo de exibição atual.

setSelected(): void;

Retornos

void

Comentários

Conjunto de APIs: PowerPointApi 1.5

Exemplos

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

// Selects the first 10 characters of the selected shape.
await PowerPoint.run(async (context) => {
  const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
  const shapeCount = shapes.getCount();
  await context.sync();
  if (shapeCount.value !== 1) {
    console.warn("You must select only one shape with text in it.");
    return;
  }
  const shape: PowerPoint.Shape = shapes.getItemAt(0);
  const textFrame: PowerPoint.TextFrame = shape.textFrame.load("textRange,hasText");
  await context.sync();
  if (textFrame.hasText != true) {
    console.warn("You must select only one shape with text in it.");
    return;
  }
  const textRange: PowerPoint.TextRange = textFrame.textRange;
  textRange.load("text");
  await context.sync();
  if (textRange.text.length < 10) {
    console.warn("You must select only one shape with at least 10 characters in it.");
    return;
  }
  const textRange10 = textRange.getSubstring(0, 10);
  textRange10.setSelected();
  await context.sync();
});

...

// Sets the range selection to the range that was saved previously.
await PowerPoint.run(async (context) => {
  const slide1: PowerPoint.Slide = context.presentation.slides.getItem(savedTextSlideSelection[0]);
  const shape1: PowerPoint.Shape = slide1.shapes.getItem(savedTextShapeSelection[0]);
  const textRange: PowerPoint.TextRange = shape1.textFrame.textRange.getSubstring(
    savedTextTextRangeStart,
    savedTextTextRangeLength,
  );
  textRange.setSelected();
  await context.sync();
});

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.TextRange é um objeto de API, o toJSON método retorna um objeto JavaScript simples (digitado como PowerPoint.Interfaces.TextRangeData) que contém cópias superficiais de todas as propriedades filho carregadas do objeto original.

toJSON(): PowerPoint.Interfaces.TextRangeData;

Retornos