PowerPoint.TextRange class

Contient le texte lié à une forme, en plus des propriétés et méthodes de manipulation du texte.

Extends

Remarques

Jeu d’API : PowerPointApi 1.4

Utilisateur

Exemples

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

Propriétés

context

Contexte de requête associé à l’objet. Cette opération connecte le processus du complément à celui de l’application hôte Office.

font

Renvoie un ShapeFont objet qui représente les attributs de police de la plage de texte.

hyperlinks

Renvoie une collection de liens hypertexte qui existent sur ce .TextRange

length

Obtient ou définit la longueur de la plage que cela TextRange représente. Lève une InvalidArgument exception lorsqu’une valeur négative est définie ou si cette valeur est supérieure à la longueur du texte disponible à partir du point de départ.

paragraphFormat

Représente le format de paragraphe de la plage de texte. Pour plus d’informations , consultez PowerPoint.ParagraphFormat .

start

Obtient ou définit un index de base zéro, relatif au bloc de texte parent, pour la position de départ de la plage que cela TextRange représente. Lève une InvalidArgument exception lorsqu’une valeur négative est définie ou si la valeur est supérieure à la longueur du texte.

text

Représente le contenu de texte brut de la plage de texte.

Méthodes

getParentTextFrame()

Renvoie l’objet PowerPoint.TextFrame parent qui contient ce TextRange.

getSubstring(start, length)

Renvoie un TextRange objet pour la sous-chaîne dans la plage donnée.

load(options)

Files d’attente de la commande pour charger les propriétés de l’objet spécifié. Vous devez contacter context.sync() avant de lire les propriétés.

load(propertyNames)

Files d’attente de la commande pour charger les propriétés de l’objet spécifié. Vous devez contacter context.sync() avant de lire les propriétés.

load(propertyNamesAndPaths)

Files d’attente de la commande pour charger les propriétés de l’objet spécifié. Vous devez contacter context.sync() avant de lire les propriétés.

setHyperlink(options)

Définit un lien hypertexte à ce TextRange sujet avec les options spécifiées. Cela supprimera tous les liens hypertexte existants sur ce TextRange.

setSelected()

Sélectionne cette option TextRange dans la vue actuelle.

toJSON()

Remplace la méthode JavaScript toJSON() afin de fournir une sortie plus utile lorsqu’un objet API est passé à JSON.stringify(). (JSON.stringify, à son tour, appelle la toJSON méthode de l’objet qui lui est passé.) Alors que l’objet d’origine PowerPoint.TextRange est un objet API, la toJSON méthode renvoie un objet JavaScript simple (typé ) PowerPoint.Interfaces.TextRangeDataqui contient des copies superficielles de toutes les propriétés enfants chargées à partir de l’objet d’origine.

Détails de la propriété

context

Contexte de requête associé à l’objet. Cette opération connecte le processus du complément à celui de l’application hôte Office.

context: RequestContext;

Valeur de propriété

font

Renvoie un ShapeFont objet qui représente les attributs de police de la plage de texte.

readonly font: PowerPoint.ShapeFont;

Valeur de propriété

Remarques

Jeu d’API : PowerPointApi 1.4

Exemples

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

Renvoie une collection de liens hypertexte qui existent sur ce .TextRange

readonly hyperlinks: PowerPoint.HyperlinkScopedCollection;

Valeur de propriété

Remarques

Jeu d’API : PowerPointApi 1.10

length

Obtient ou définit la longueur de la plage que cela TextRange représente. Lève une InvalidArgument exception lorsqu’une valeur négative est définie ou si cette valeur est supérieure à la longueur du texte disponible à partir du point de départ.

length: number;

Valeur de propriété

number

Remarques

Jeu d’API : PowerPointApi 1.5

paragraphFormat

Représente le format de paragraphe de la plage de texte. Pour plus d’informations , consultez PowerPoint.ParagraphFormat .

readonly paragraphFormat: PowerPoint.ParagraphFormat;

Valeur de propriété

Remarques

Jeu d’API : PowerPointApi 1.4

Exemples

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

Obtient ou définit un index de base zéro, relatif au bloc de texte parent, pour la position de départ de la plage que cela TextRange représente. Lève une InvalidArgument exception lorsqu’une valeur négative est définie ou si la valeur est supérieure à la longueur du texte.

start: number;

Valeur de propriété

number

Remarques

Jeu d’API : PowerPointApi 1.5

text

Représente le contenu de texte brut de la plage de texte.

text: string;

Valeur de propriété

string

Remarques

Jeu d’API : PowerPointApi 1.4

Détails de la méthode

getParentTextFrame()

Renvoie l’objet PowerPoint.TextFrame parent qui contient ce TextRange.

getParentTextFrame(): PowerPoint.TextFrame;

Retours

Remarques

Jeu d’API : PowerPointApi 1.5

Exemples

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

Renvoie un TextRange objet pour la sous-chaîne dans la plage donnée.

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

Paramètres

start

number

Index en base zéro du premier caractère obtenu à partir de la plage de texte.

length

number

Facultatif. Nombre de caractères à renvoyer dans la nouvelle plage de texte. Si la longueur est omise, tous les caractères du début à la fin du dernier paragraphe de la plage de texte seront renvoyés.

Retours

Remarques

Jeu d’API : PowerPointApi 1.4

load(options)

Files d’attente de la commande pour charger les propriétés de l’objet spécifié. Vous devez contacter context.sync() avant de lire les propriétés.

load(options?: PowerPoint.Interfaces.TextRangeLoadOptions): PowerPoint.TextRange;

Paramètres

options
PowerPoint.Interfaces.TextRangeLoadOptions

Fournit des options pour les propriétés de l’objet à charger.

Retours

load(propertyNames)

Files d’attente de la commande pour charger les propriétés de l’objet spécifié. Vous devez contacter context.sync() avant de lire les propriétés.

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

Paramètres

propertyNames

string | string[]

Chaîne délimitée par des virgules ou tableau de chaînes spécifiant les propriétés à charger.

Retours

load(propertyNamesAndPaths)

Files d’attente de la commande pour charger les propriétés de l’objet spécifié. Vous devez contacter context.sync() avant de lire les propriétés.

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

Paramètres

propertyNamesAndPaths

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

propertyNamesAndPaths.select est une chaîne délimitée par des virgules qui spécifie les propriétés à charger, et propertyNamesAndPaths.expand est une chaîne délimitée par des virgules qui spécifie les propriétés de navigation à charger.

Retours

Définit un lien hypertexte à ce TextRange sujet avec les options spécifiées. Cela supprimera tous les liens hypertexte existants sur ce TextRange.

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

Paramètres

options
PowerPoint.HyperlinkAddOptions

Facultatif. Options du lien hypertexte.

Retours

Objet PowerPoint.Hyperlink nouvellement créé.

Remarques

Jeu d’API : PowerPointApi 1.10

setSelected()

Sélectionne cette option TextRange dans la vue actuelle.

setSelected(): void;

Retours

void

Remarques

Jeu d’API : PowerPointApi 1.5

Exemples

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

Remplace la méthode JavaScript toJSON() afin de fournir une sortie plus utile lorsqu’un objet API est passé à JSON.stringify(). (JSON.stringify, à son tour, appelle la toJSON méthode de l’objet qui lui est passé.) Alors que l’objet d’origine PowerPoint.TextRange est un objet API, la toJSON méthode renvoie un objet JavaScript simple (typé ) PowerPoint.Interfaces.TextRangeDataqui contient des copies superficielles de toutes les propriétés enfants chargées à partir de l’objet d’origine.

toJSON(): PowerPoint.Interfaces.TextRangeData;

Retours