Share via


PowerPoint.TextRange class

Contiene el texto que hay unido a una forma, además de las propiedades y los métodos de manipulación del texto.

Extends

Comentarios

[ Conjunto de API: PowerPointApi 1.4 ]

Propiedades

context

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

font

Devuelve un ShapeFont objeto que representa los atributos de fuente del intervalo de texto.

length

Obtiene o establece la longitud del intervalo que representa.TextRange Produce una InvalidArgument excepción cuando se establece con un valor negativo o si el valor es mayor que la longitud del texto disponible desde el punto inicial.

paragraphFormat

Representa el formato de párrafo del intervalo de texto. Vea PowerPoint.ParagraphFormat para obtener más información.

start

Obtiene o establece el índice de base cero, en relación con el marco de texto primario, para la posición inicial del intervalo que representa TextRange . Produce una InvalidArgument excepción cuando se establece con un valor negativo o si el valor es mayor que la longitud del texto.

text

Indica el contenido de texto sin formato del intervalo de texto.

Métodos

getParentTextFrame()

Devuelve el objeto PowerPoint.TextFrame primario que contiene este TextRangeobjeto .

getSubstring(start, length)

Devuelve un TextRange objeto para la subcadena del intervalo especificado.

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.

setSelected()

Selecciona esta TextRange opción en la vista actual.

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 PowerPoint.TextRange original es un objeto de API, el toJSON método devuelve un objeto JavaScript sin formato (escrito como PowerPoint.Interfaces.TextRangeData) 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

font

Devuelve un ShapeFont objeto que representa los atributos de fuente del intervalo de texto.

readonly font: PowerPoint.ShapeFont;

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

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

length

Obtiene o establece la longitud del intervalo que representa.TextRange Produce una InvalidArgument excepción cuando se establece con un valor negativo o si el valor es mayor que la longitud del texto disponible desde el punto inicial.

length: number;

Valor de propiedad

number

Comentarios

[ Conjunto de API: PowerPointApi 1.5 ]

paragraphFormat

Representa el formato de párrafo del intervalo de texto. Vea PowerPoint.ParagraphFormat para obtener más información.

readonly paragraphFormat: PowerPoint.ParagraphFormat;

Valor de propiedad

Comentarios

[ Conjunto de API: PowerPointApi 1.4 ]

start

Obtiene o establece el índice de base cero, en relación con el marco de texto primario, para la posición inicial del intervalo que representa TextRange . Produce una InvalidArgument excepción cuando se establece con un valor negativo o si el valor es mayor que la longitud del texto.

start: number;

Valor de propiedad

number

Comentarios

[ Conjunto de API: PowerPointApi 1.5 ]

text

Indica el contenido de texto sin formato del intervalo de texto.

text: string;

Valor de propiedad

string

Comentarios

[ Conjunto de API: PowerPointApi 1.4 ]

Detalles del método

getParentTextFrame()

Devuelve el objeto PowerPoint.TextFrame primario que contiene este TextRangeobjeto .

getParentTextFrame(): PowerPoint.TextFrame;

Devoluciones

Comentarios

[ Conjunto de API: PowerPointApi 1.5 ]

getSubstring(start, length)

Devuelve un TextRange objeto para la subcadena del intervalo especificado.

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

Parámetros

start

number

Índice de base cero del primer carácter que se obtiene del intervalo de texto.

length

number

Opcional. Número de caracteres que se devolverán en el nuevo intervalo de texto. Si se omite length, se devolverán todos los caracteres desde el principio hasta el final del último párrafo del intervalo de texto.

Devoluciones

Comentarios

[ Conjunto de API: PowerPointApi 1.4 ]

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

Parámetros

options
PowerPoint.Interfaces.TextRangeLoadOptions

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

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

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

setSelected()

Selecciona esta TextRange opción en la vista actual.

setSelected(): void;

Devoluciones

void

Comentarios

[ Conjunto de API: PowerPointApi 1.5 ]

Ejemplos

// 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 = 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 = shapes.getItemAt(0);
  const 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 = 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 = context.presentation.slides.getItem(savedTextSlideSelection[0]);
  const shape1 = slide1.shapes.getItem(savedTextShapeSelection[0]);
  const textRange = shape1.textFrame.textRange.getSubstring(savedTextTextRangeStart, savedTextTextRangeLength);
  textRange.setSelected();
  await context.sync();
});

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 PowerPoint.TextRange original es un objeto de API, el toJSON método devuelve un objeto JavaScript sin formato (escrito como PowerPoint.Interfaces.TextRangeData) que contiene copias superficiales de las propiedades secundarias cargadas del objeto original.

toJSON(): PowerPoint.Interfaces.TextRangeData;

Devoluciones