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 ]
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: PowerPoint.TextRange = context.presentation.getSelectedTextRange();
textRange.font.color = "green";
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. |
| font | Devuelve un |
| hyperlinks | Devuelve una colección de hipervínculos que existen en este |
| length | Obtiene o establece la longitud del intervalo que representa. |
| paragraph |
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 |
| text | Indica el contenido de texto sin formato del intervalo de texto. |
Métodos
| get |
Devuelve el objeto PowerPoint.TextFrame primario que contiene este |
| get |
Devuelve un |
| load(options) | Pone en cola un comando para cargar las propiedades especificadas del objeto. Debe llamar a |
| load(property |
Pone en cola un comando para cargar las propiedades especificadas del objeto. Debe llamar a |
| load(property |
Pone en cola un comando para cargar las propiedades especificadas del objeto. Debe llamar a |
| set |
Establece un hipervínculo con |
| set |
Selecciona esta |
| toJSON() | Invalida el método JavaScript |
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: PowerPoint.TextRange = context.presentation.getSelectedTextRange();
textRange.font.color = "green";
await context.sync();
});
hyperlinks
Nota
Esta API se ofrece a los desarrolladores como versión preliminar y puede cambiar en función de los comentarios que recibamos. No utilice esta API en un entorno de producción.
Devuelve una colección de hipervínculos que existen en este TextRange.
readonly hyperlinks: PowerPoint.HyperlinkScopedCollection;
Valor de propiedad
Comentarios
[ Conjunto de API: PowerPointApi BETA (SOLO VERSIÓN PRELIMINAR) ]
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
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 ]
Ejemplos
// 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");
await context.sync();
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
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
text
Indica el contenido de texto sin formato del intervalo de texto.
text: string;
Valor de propiedad
string
Comentarios
Detalles del método
getParentTextFrame()
Devuelve el objeto PowerPoint.TextFrame primario que contiene este TextRangeobjeto .
getParentTextFrame(): PowerPoint.TextFrame;
Devoluciones
Comentarios
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
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
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
setHyperlink(options)
Nota
Esta API se ofrece a los desarrolladores como versión preliminar y puede cambiar en función de los comentarios que recibamos. No utilice esta API en un entorno de producción.
Establece un hipervínculo con TextRange las opciones especificadas. Esto eliminará todos los hipervínculos existentes en este TextRange.
setHyperlink(options?: PowerPoint.HyperlinkAddOptions): PowerPoint.Hyperlink;
Parámetros
- options
- PowerPoint.HyperlinkAddOptions
Opcional. Opciones del hipervínculo.
Devoluciones
Objeto PowerPoint.Hyperlink recién creado.
Comentarios
[ Conjunto de API: PowerPointApi BETA (SOLO VERSIÓN PRELIMINAR) ]
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: 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()
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.TextRange 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;