Word.ContentControl class

Stellt ein Inhaltssteuerelement dar. Inhaltssteuerelemente sind gebunden und potenziell beschrifteten Bereiche in einem Dokument, das als Container für bestimmte Arten von Inhalten dienen. Einzelne Inhaltssteuerelemente können Inhalte wie Bilder, Tabellen oder Absätze mit formatiertem Text enthalten. Derzeit werden nur Rich-Text-, Nur-Text- und Kontrollkästchen-Inhaltssteuerelemente unterstützt.

Extends

Hinweise

[ API-Satz: WordApi 1.1 ]

Beispiele

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Create a proxy object for the content controls collection.
    const contentControls = context.document.contentControls;

    // Queue a command to load the id property for all of the content controls.
    contentControls.load('id');

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    if (contentControls.items.length === 0) {
        console.log('No content control found.');
    }
    else {
        // Queue a command to load the properties on the first content control.
        contentControls.items[0].load(  'appearance,' +
                                        'cannotDelete,' +
                                        'cannotEdit,' +
                                        'color,' +
                                        'id,' +
                                        'placeHolderText,' +
                                        'removeWhenEdited,' +
                                        'title,' +
                                        'text,' +
                                        'type,' +
                                        'style,' +
                                        'tag,' +
                                        'font/size,' +
                                        'font/name,' +
                                        'font/color');

        // Synchronize the document state by executing the queued commands,
        // and return a promise to indicate task completion.
        await context.sync();
        console.log('Property values of the first content control:' +
            '   ----- appearance: ' + contentControls.items[0].appearance +
            '   ----- cannotDelete: ' + contentControls.items[0].cannotDelete +
            '   ----- cannotEdit: ' + contentControls.items[0].cannotEdit +
            '   ----- color: ' + contentControls.items[0].color +
            '   ----- id: ' + contentControls.items[0].id +
            '   ----- placeHolderText: ' + contentControls.items[0].placeholderText +
            '   ----- removeWhenEdited: ' + contentControls.items[0].removeWhenEdited +
            '   ----- title: ' + contentControls.items[0].title +
            '   ----- text: ' + contentControls.items[0].text +
            '   ----- type: ' + contentControls.items[0].type +
            '   ----- style: ' + contentControls.items[0].style +
            '   ----- tag: ' + contentControls.items[0].tag +
            '   ----- font size: ' + contentControls.items[0].font.size +
            '   ----- font name: ' + contentControls.items[0].font.name +
            '   ----- font color: ' + contentControls.items[0].font.color);
    }
});

Eigenschaften

appearance

Gibt die Darstellung des Inhaltssteuerelements an. Der Wert kann "BoundingBox", "Tags" oder "Hidden" sein.

cannotDelete

Gibt einen Wert an, der angibt, ob der Benutzer das Inhaltssteuerelement löschen kann. Sich gegenseitig ausschließend mit removeWhenEdited.

cannotEdit

Gibt einen Wert an, der angibt, ob der Benutzer den Inhalt des Inhaltssteuerelements bearbeiten kann.

color

Gibt die Farbe des Inhaltssteuerelements an. Die Farbe wird im Format "#RRGGBB" oder unter Verwendung des Farbnamens angegeben.

contentControls

Ruft die Auflistung von Inhaltssteuerelement-Objekten im Inhaltssteuerelement ab.

context

Der Anforderungskontext, der dem -Objekt zugeordnet ist. Dadurch wird der Prozess des Add-Ins mit dem Prozess der Office-Hostanwendung verbunden.

font

Ruft das Textformat des Inhaltssteuerelements ab. Verwenden Sie diese zum Abrufen und Festlegen der Schriftart, Größe, Farbe und andere Eigenschaften.

id

Ruft eine Ganzzahl ab, die den Inhaltssteuerelement-Bezeichner darstellt.

inlinePictures

Ruft die Auflistung von InlinePicture-Objekten im Inhaltssteuerelement ab. Die Auflistung enthält keine unverankerten Bilder.

paragraphs

Ruft die Auflistung von Absatzobjekten im Inhaltssteuerelement ab.

parentContentControl

Ruft das Inhaltssteuerelement ab, das das Inhaltssteuerelement enthält. Löst einen Fehler aus ItemNotFound , wenn kein übergeordnetes Inhaltssteuerelement vorhanden ist.

placeholderText

Gibt den Platzhaltertext des Inhaltssteuerelements an. Abgeblendeter Text wird angezeigt, wenn das Inhaltssteuerelement leer ist.

Hinweis: Der Set-Vorgang für diese Eigenschaft wird in Word im Web nicht unterstützt.

removeWhenEdited

Gibt einen Wert an, der angibt, ob das Inhaltssteuerelement entfernt wird, nachdem es bearbeitet wurde. Sich gegenseitig ausschließend mit CannotDelete.

style

Gibt den Formatvorlagennamen für das Inhaltssteuerelement an. Verwenden Sie diese Eigenschaft für benutzerdefinierte Formatvorlagen und lokalisierte Formatvorlagennamen. Informationen zur Verwendung der integrierten Formatvorlagen, die zwischen Gebietsschemas portabel sind, finden Sie unter der Eigenschaft "styleBuiltIn".

tag

Gibt ein Tag zum Identifizieren eines Inhaltssteuerelements an.

text

Ruft den Text des Inhaltssteuerelements ab.

title

Gibt den Titel für ein Inhaltssteuerelement an.

type

Ruft den Typen des Inhaltssteuerelements ab. Derzeit werden nur Rich-Text-, Nur-Text- und Kontrollkästchen-Inhaltssteuerelemente unterstützt.

Methoden

clear()

Löscht den Inhalt des Inhaltssteuerelements. Der Benutzer kann den Rückgängig-Vorgang auf den gelöschten Inhalt durchführen.

delete(keepContent)

Löscht das Inhaltssteuerelement und dessen Inhalt. Wenn keepContent auf true festgelegt ist, wird der Inhalt nicht gelöscht.

getHtml()

Ruft eine HTML-Darstellung des Inhaltssteuerelementobjekts ab. Wenn sie in einer Webseite oder einem HTML-Viewer gerendert wird, ist die Formatierung eine enge, aber nicht exakte Übereinstimmung mit der Formatierung des Dokuments. Diese Methode gibt nicht genau denselben HTML-Code für dasselbe Dokument auf verschiedenen Plattformen (Windows, Mac, Word im Web usw.) zurück. Wenn Sie genaue Genauigkeit oder plattformübergreifende Konsistenz benötigen, verwenden ContentControl.getOoxml() Und konvertieren Sie den zurückgegebenen XML-Code in HTML.

getOoxml()

Ruft die Office Open XML (OOXML)-Darstellung des Inhaltssteuerelement-Objekts ab.

insertBreak(breakType, insertLocation)

Fügt an der angegebenen Position im Hauptdokument einen Umbruch ein. Diese Methode kann nicht mit den Inhaltssteuerelementen "RichTextTable", "RichTextTableRow" und "RichTextTableCell" verwendet werden.

insertFileFromBase64(base64File, insertLocation)

Fügt ein Dokument an der angegebenen Position in das Inhaltssteuerelement ein.

insertHtml(html, insertLocation)

Fügt an der angegebenen Position HTML ein.

insertOoxml(ooxml, insertLocation)

Fügt OOXML an der angegebenen Position in das Inhaltssteuerelement ein.

insertParagraph(paragraphText, insertLocation)

Fügt an der angegebenen Position einen Absatz ein.

insertText(text, insertLocation)

Fügt an der angegebenen Position Text in das Inhaltssteuerelement ein.

load(options)

Stellt einen Befehl zum Laden der angegebenen Eigenschaften des Objekts in die Warteschlange ein. Vor dem Lesen der Eigenschaften müssen Sie "context.sync()" aufrufen.

load(propertyNames)

Stellt einen Befehl zum Laden der angegebenen Eigenschaften des Objekts in die Warteschlange ein. Vor dem Lesen der Eigenschaften müssen Sie "context.sync()" aufrufen.

load(propertyNamesAndPaths)

Stellt einen Befehl zum Laden der angegebenen Eigenschaften des Objekts in die Warteschlange ein. Vor dem Lesen der Eigenschaften müssen Sie "context.sync()" aufrufen.

search(searchText, searchOptions)

Führt eine Suche mit den angegebenen SearchOptions für den Bereich des Inhaltssteuerelementobjekts aus. Die Suchergebnisse sind eine Sammlung von Bereichsobjekten.

select(selectionMode)

Wählt das Inhaltssteuerelement aus. Dies bewirkt, dass Word einen Bildlauf zur Auswahl durchführt.

select(selectionModeString)

Wählt das Inhaltssteuerelement aus. Dies bewirkt, dass Word einen Bildlauf zur Auswahl durchführt.

set(properties, options)

Legt mehrere Eigenschaften eines Objekts gleichzeitig fest. Sie können entweder ein einfaches Objekt mit den entsprechenden Eigenschaften oder ein anderes API-Objekt desselben Typs übergeben.

set(properties)

Legt mehrere Eigenschaften für das -Objekt gleichzeitig fest, basierend auf einem vorhandenen geladenen Objekt.

toJSON()

Überschreibt die JavaScript-Methode toJSON() , um eine nützlichere Ausgabe bereitzustellen, wenn ein API-Objekt an JSON.stringify()übergeben wird. (JSON.stringifyruft wiederum die toJSON -Methode des Objekts auf, das an das Objekt übergeben wird.) Die ursprüngliche Word. ContentControl-Objekt ist ein API-Objekt, die toJSON Methode gibt ein einfaches JavaScript-Objekt (typisiert als Word.Interfaces.ContentControlData) zurück, das flache Kopien aller geladenen untergeordneten Eigenschaften aus dem ursprünglichen Objekt enthält.

track()

Nachverfolgung des Objekts zwecks automatischer Anpassung auf der Grundlage der umgebenden Änderungen im Dokument. Dieser Aufruf ist eine Kurzform für context.trackedObjects.add(thisObject). Wenn Sie dieses Objekt über .sync Aufrufe hinweg und außerhalb der sequenziellen Ausführung eines ".run"-Batches verwenden und beim Festlegen einer Eigenschaft oder beim Aufrufen einer Methode für das Objekt den Fehler "InvalidObjectPath" erhalten, müssen Sie das Objekt der nachverfolgten Objektauflistung hinzufügen, als das Objekt zum ersten Mal erstellt wurde. Wenn dieses Objekt Teil einer Auflistung ist, sollten Sie auch die übergeordnete Auflistung nachverfolgen.

untrack()

Gibt den diesem Objekt zugewiesenen Arbeitsspeicher frei, wenn das Objekt zuvor nachverfolgt wurde. Dieser Aufruf ist die Kurzform für context.trackedObjects.remove(thisObject). Viele nachverfolgte Objekte verlangsamen die Ausführung der Hostanwendung, also achten Sie darauf, alle hinzugefügten Objekte nach abgeschlossener Verwendung freizugeben. Sie müssen aufrufen context.sync() , bevor die Speicherfreigabe wirksam wird.

Details zur Eigenschaft

appearance

Gibt die Darstellung des Inhaltssteuerelements an. Der Wert kann "BoundingBox", "Tags" oder "Hidden" sein.

appearance: Word.ContentControlAppearance | "BoundingBox" | "Tags" | "Hidden";

Eigenschaftswert

Word.ContentControlAppearance | "BoundingBox" | "Tags" | "Hidden"

Hinweise

[ API-Satz: WordApi 1.1 ]

cannotDelete

Gibt einen Wert an, der angibt, ob der Benutzer das Inhaltssteuerelement löschen kann. Sich gegenseitig ausschließend mit removeWhenEdited.

cannotDelete: boolean;

Eigenschaftswert

boolean

Hinweise

[ API-Satz: WordApi 1.1 ]

cannotEdit

Gibt einen Wert an, der angibt, ob der Benutzer den Inhalt des Inhaltssteuerelements bearbeiten kann.

cannotEdit: boolean;

Eigenschaftswert

boolean

Hinweise

[ API-Satz: WordApi 1.1 ]

color

Gibt die Farbe des Inhaltssteuerelements an. Die Farbe wird im Format "#RRGGBB" oder unter Verwendung des Farbnamens angegeben.

color: string;

Eigenschaftswert

string

Hinweise

[ API-Satz: WordApi 1.1 ]

contentControls

Ruft die Auflistung von Inhaltssteuerelement-Objekten im Inhaltssteuerelement ab.

readonly contentControls: Word.ContentControlCollection;

Eigenschaftswert

Hinweise

[ API-Satz: WordApi 1.1 ]

context

Der Anforderungskontext, der dem -Objekt zugeordnet ist. Dadurch wird der Prozess des Add-Ins mit dem Prozess der Office-Hostanwendung verbunden.

context: RequestContext;

Eigenschaftswert

font

Ruft das Textformat des Inhaltssteuerelements ab. Verwenden Sie diese zum Abrufen und Festlegen der Schriftart, Größe, Farbe und andere Eigenschaften.

readonly font: Word.Font;

Eigenschaftswert

Hinweise

[ API-Satz: WordApi 1.1 ]

id

Ruft eine Ganzzahl ab, die den Inhaltssteuerelement-Bezeichner darstellt.

readonly id: number;

Eigenschaftswert

number

Hinweise

[ API-Satz: WordApi 1.1 ]

inlinePictures

Ruft die Auflistung von InlinePicture-Objekten im Inhaltssteuerelement ab. Die Auflistung enthält keine unverankerten Bilder.

readonly inlinePictures: Word.InlinePictureCollection;

Eigenschaftswert

Hinweise

[ API-Satz: WordApi 1.1 ]

paragraphs

Ruft die Auflistung von Absatzobjekten im Inhaltssteuerelement ab.

readonly paragraphs: Word.ParagraphCollection;

Eigenschaftswert

Hinweise

[ API-Satz: WordApi 1.1 ]

Wichtig: Für die Anforderungssätze 1.1 und 1.2 werden Absätze in Tabellen, die vollständig in diesem Inhaltssteuerelement enthalten sind, nicht zurückgegeben. Ab Anforderungssatz 1.3 werden auch Absätze in solchen Tabellen zurückgegeben.

parentContentControl

Ruft das Inhaltssteuerelement ab, das das Inhaltssteuerelement enthält. Löst einen Fehler aus ItemNotFound , wenn kein übergeordnetes Inhaltssteuerelement vorhanden ist.

readonly parentContentControl: Word.ContentControl;

Eigenschaftswert

Hinweise

[ API-Satz: WordApi 1.1 ]

placeholderText

Gibt den Platzhaltertext des Inhaltssteuerelements an. Abgeblendeter Text wird angezeigt, wenn das Inhaltssteuerelement leer ist.

Hinweis: Der Set-Vorgang für diese Eigenschaft wird in Word im Web nicht unterstützt.

placeholderText: string;

Eigenschaftswert

string

Hinweise

[ API-Satz: WordApi 1.1 ]

removeWhenEdited

Gibt einen Wert an, der angibt, ob das Inhaltssteuerelement entfernt wird, nachdem es bearbeitet wurde. Sich gegenseitig ausschließend mit CannotDelete.

removeWhenEdited: boolean;

Eigenschaftswert

boolean

Hinweise

[ API-Satz: WordApi 1.1 ]

style

Gibt den Formatvorlagennamen für das Inhaltssteuerelement an. Verwenden Sie diese Eigenschaft für benutzerdefinierte Formatvorlagen und lokalisierte Formatvorlagennamen. Informationen zur Verwendung der integrierten Formatvorlagen, die zwischen Gebietsschemas portabel sind, finden Sie unter der Eigenschaft "styleBuiltIn".

style: string;

Eigenschaftswert

string

Hinweise

[ API-Satz: WordApi 1.1 ]

tag

Gibt ein Tag zum Identifizieren eines Inhaltssteuerelements an.

tag: string;

Eigenschaftswert

string

Hinweise

[ API-Satz: WordApi 1.1 ]

Beispiele

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/10-content-controls/insert-and-change-content-controls.yaml

// Traverses each paragraph of the document and wraps a content control on each with either a even or odd tags.
await Word.run(async (context) => {
  let paragraphs = context.document.body.paragraphs;
  paragraphs.load("$none"); // Don't need any properties; just wrap each paragraph with a content control.

  await context.sync();

  for (let i = 0; i < paragraphs.items.length; i++) {
    let contentControl = paragraphs.items[i].insertContentControl();
    // For even, tag "even".
    if (i % 2 === 0) {
      contentControl.tag = "even";
    } else {
      contentControl.tag = "odd";
    }
  }
  console.log("Content controls inserted: " + paragraphs.items.length);

  await context.sync();
});

text

Ruft den Text des Inhaltssteuerelements ab.

readonly text: string;

Eigenschaftswert

string

Hinweise

[ API-Satz: WordApi 1.1 ]

title

Gibt den Titel für ein Inhaltssteuerelement an.

title: string;

Eigenschaftswert

string

Hinweise

[ API-Satz: WordApi 1.1 ]

type

Ruft den Typen des Inhaltssteuerelements ab. Derzeit werden nur Rich-Text-, Nur-Text- und Kontrollkästchen-Inhaltssteuerelemente unterstützt.

readonly type: Word.ContentControlType | "Unknown" | "RichTextInline" | "RichTextParagraphs" | "RichTextTableCell" | "RichTextTableRow" | "RichTextTable" | "PlainTextInline" | "PlainTextParagraph" | "Picture" | "BuildingBlockGallery" | "CheckBox" | "ComboBox" | "DropDownList" | "DatePicker" | "RepeatingSection" | "RichText" | "PlainText";

Eigenschaftswert

Word.ContentControlType | "Unknown" | "RichTextInline" | "RichTextParagraphs" | "RichTextTableCell" | "RichTextTableRow" | "RichTextTable" | "PlainTextInline" | "PlainTextParagraph" | "Picture" | "BuildingBlockGallery" | "CheckBox" | "ComboBox" | "DropDownList" | "DatePicker" | "RepeatingSection" | "RichText" | "PlainText"

Hinweise

[ API-Satz: WordApi 1.1 ]

Details zur Methode

clear()

Löscht den Inhalt des Inhaltssteuerelements. Der Benutzer kann den Rückgängig-Vorgang auf den gelöschten Inhalt durchführen.

clear(): void;

Gibt zurück

void

Hinweise

[ API-Satz: WordApi 1.1 ]

Beispiele

// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Create a proxy object for the content controls collection.
    const contentControls = context.document.contentControls;
    
    // Queue a command to load the content controls collection.
    contentControls.load('text');
     
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
        
    if (contentControls.items.length === 0) {
        console.log("There isn't a content control in this document.");
    } else {
        // Queue a command to clear the contents of the first content control.
        contentControls.items[0].clear();

        // Synchronize the document state by executing the queued commands, 
        // and return a promise to indicate task completion.
        await context.sync();
        console.log('Content control cleared of contents.');
    }
});

delete(keepContent)

Löscht das Inhaltssteuerelement und dessen Inhalt. Wenn keepContent auf true festgelegt ist, wird der Inhalt nicht gelöscht.

delete(keepContent: boolean): void;

Parameter

keepContent

boolean

Erforderlich. Gibt an, ob der Inhalt mit dem Inhaltssteuerelement gelöscht werden soll. Wenn keepContent auf true festgelegt ist, wird der Inhalt nicht gelöscht.

Gibt zurück

void

Hinweise

[ API-Satz: WordApi 1.1 ]

Beispiele

// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Create a proxy object for the content controls collection.
    const contentControls = context.document.contentControls;
    
    // Queue a command to load the content controls collection.
    contentControls.load('text');
     
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
        
    if (contentControls.items.length === 0) {
        console.log("There isn't a content control in this document.");
    } else {            
        // Queue a command to delete the first content control. 
        // The contents will remain in the document.
        contentControls.items[0].delete(true);

        // Synchronize the document state by executing the queued commands, 
        // and return a promise to indicate task completion.
        await context.sync();
        console.log('Content control cleared of contents.'); 
    }
});
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/10-content-controls/content-control-ondeleted-event.yaml

await Word.run(async (context) => {
  const contentControls = context.document.contentControls.getByTag("forTesting");
  contentControls.load("items");
  await context.sync();

  if (contentControls.items.length === 0) {
    console.log("There are no content controls in this document.");
  } else {
    console.log("Control to be deleted:");
    console.log(contentControls.items[0]);
    contentControls.items[0].delete(false);
    await context.sync();
  }
});

getHtml()

Ruft eine HTML-Darstellung des Inhaltssteuerelementobjekts ab. Wenn sie in einer Webseite oder einem HTML-Viewer gerendert wird, ist die Formatierung eine enge, aber nicht exakte Übereinstimmung mit der Formatierung des Dokuments. Diese Methode gibt nicht genau denselben HTML-Code für dasselbe Dokument auf verschiedenen Plattformen (Windows, Mac, Word im Web usw.) zurück. Wenn Sie genaue Genauigkeit oder plattformübergreifende Konsistenz benötigen, verwenden ContentControl.getOoxml() Und konvertieren Sie den zurückgegebenen XML-Code in HTML.

getHtml(): OfficeExtension.ClientResult<string>;

Gibt zurück

Hinweise

[ API-Satz: WordApi 1.1 ]

Beispiele

// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Create a proxy object for the content controls collection that contains a specific tag.
    const contentControlsWithTag = context.document.contentControls.getByTag('Customer-Address');
    
    // Queue a command to load the tag property for all of content controls.
    contentControlsWithTag.load('tag');
     
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
    if (contentControlsWithTag.items.length === 0) {
        console.log('No content control found.');
    }
    else {
        // Queue a command to get the HTML contents of the first content control.
        const html = contentControlsWithTag.items[0].getHtml();
    
        // Synchronize the document state by executing the queued commands, 
        // and return a promise to indicate task completion.
        await context.sync();
        console.log('Content control HTML: ' + html.value);
    }
});

getOoxml()

Ruft die Office Open XML (OOXML)-Darstellung des Inhaltssteuerelement-Objekts ab.

getOoxml(): OfficeExtension.ClientResult<string>;

Gibt zurück

Hinweise

[ API-Satz: WordApi 1.1 ]

Beispiele

// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Create a proxy object for the content controls collection.
    const contentControls = context.document.contentControls;
    
    // Queue a command to load the id property for all of the content controls.
    contentControls.load('id');
     
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
    if (contentControls.items.length === 0) {
        console.log('No content control found.');
    }
    else {
        // Queue a command to get the OOXML contents of the first content control.
        const ooxml = contentControls.items[0].getOoxml();
    
        // Synchronize the document state by executing the queued commands, 
        // and return a promise to indicate task completion.
        await context.sync();
        console.log('Content control OOXML: ' + ooxml.value);
    }
});

insertBreak(breakType, insertLocation)

Fügt an der angegebenen Position im Hauptdokument einen Umbruch ein. Diese Methode kann nicht mit den Inhaltssteuerelementen "RichTextTable", "RichTextTableRow" und "RichTextTableCell" verwendet werden.

insertBreak(breakType: Word.BreakType | "Page" | "Next" | "SectionNext" | "SectionContinuous" | "SectionEven" | "SectionOdd" | "Line", insertLocation: Word.InsertLocation.start | Word.InsertLocation.end | Word.InsertLocation.before | Word.InsertLocation.after | "Start" | "End" | "Before" | "After"): void;

Parameter

breakType

Word.BreakType | "Page" | "Next" | "SectionNext" | "SectionContinuous" | "SectionEven" | "SectionOdd" | "Line"

Erforderlich. Typ der Unterbrechung.

insertLocation

start | end | before | after | "Start" | "End" | "Before" | "After"

Erforderlich. Der Wert muss "Start", "End", "Before" oder "After" sein.

Gibt zurück

void

Hinweise

[ API-Satz: WordApi 1.1 ]

Beispiele

// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Create a proxy object for the content controls collection.
    const contentControls = context.document.contentControls;
    
    // Queue a command to load the id property for all of content controls.
    contentControls.load('id');
    
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    // We now will have access to the content control collection.
    await context.sync();
    if (contentControls.items.length === 0) {
        console.log('No content control found.');
    }
    else {
        // Queue a command to insert a page break after the first content control.
        contentControls.items[0].insertBreak(Word.BreakType.page, Word.InsertLocation.after);
        
        // Synchronize the document state by executing the queued commands, 
        // and return a promise to indicate task completion.
        await context.sync();
        console.log('Inserted a page break after the first content control.');    
    }
});

insertFileFromBase64(base64File, insertLocation)

Fügt ein Dokument an der angegebenen Position in das Inhaltssteuerelement ein.

insertFileFromBase64(base64File: string, insertLocation: Word.InsertLocation.replace | Word.InsertLocation.start | Word.InsertLocation.end | "Replace" | "Start" | "End"): Word.Range;

Parameter

base64File

string

Erforderlich. Der Base64-codierte Inhalt einer .docx Datei.

insertLocation

replace | start | end | "Replace" | "Start" | "End"

Erforderlich. Der Wert muss "Replace", "Start" oder "End" sein. "Replace" kann nicht mit den Inhaltssteuerelementen "RichTextTable" und "RichTextTableRow" verwendet werden.

Gibt zurück

Hinweise

[ API-Satz: WordApi 1.1 ]

Hinweis: Das Einfügen wird nicht unterstützt, wenn das eingefügte Dokument ein ActiveX-Steuerelement (wahrscheinlich in einem Formularfeld) enthält. Erwägen Sie, ein solches Formularfeld durch ein Inhaltssteuerelement oder eine andere für Ihr Szenario geeignete Option zu ersetzen.

insertHtml(html, insertLocation)

Fügt an der angegebenen Position HTML ein.

insertHtml(html: string, insertLocation: Word.InsertLocation.replace | Word.InsertLocation.start | Word.InsertLocation.end | "Replace" | "Start" | "End"): Word.Range;

Parameter

html

string

Erforderlich. Der in das Inhaltssteuerelement einzufügende HTML-Code.

insertLocation

replace | start | end | "Replace" | "Start" | "End"

Erforderlich. Der Wert muss "Replace", "Start" oder "End" sein. "Replace" kann nicht mit den Inhaltssteuerelementen "RichTextTable" und "RichTextTableRow" verwendet werden.

Gibt zurück

Hinweise

[ API-Satz: WordApi 1.1 ]

Beispiele

// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Create a proxy object for the content controls collection.
    const contentControls = context.document.contentControls;
    
    // Queue a command to load the id property for all of the content controls.
    contentControls.load('id');
     
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
    if (contentControls.items.length === 0) {
        console.log('No content control found.');
    }
    else {
        // Queue a command to put HTML into the contents of the first content control.
        contentControls.items[0].insertHtml(
            '<strong>HTML content inserted into the content control.</strong>',
            'Start');
    
        // Synchronize the document state by executing the queued commands, 
        // and return a promise to indicate task completion.
        await context.sync();
        console.log('Inserted HTML in the first content control.');
    }
});

insertOoxml(ooxml, insertLocation)

Fügt OOXML an der angegebenen Position in das Inhaltssteuerelement ein.

insertOoxml(ooxml: string, insertLocation: Word.InsertLocation.replace | Word.InsertLocation.start | Word.InsertLocation.end | "Replace" | "Start" | "End"): Word.Range;

Parameter

ooxml

string

Erforderlich. Die OOXML, die in das Inhaltssteuerelement eingefügt werden soll.

insertLocation

replace | start | end | "Replace" | "Start" | "End"

Erforderlich. Der Wert muss "Replace", "Start" oder "End" sein. "Replace" kann nicht mit den Inhaltssteuerelementen "RichTextTable" und "RichTextTableRow" verwendet werden.

Gibt zurück

Hinweise

[ API-Satz: WordApi 1.1 ]

Beispiele

// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Create a proxy object for the content controls collection.
    const contentControls = context.document.contentControls;
    
    // Queue a command to load the id property for all of the content controls.
    contentControls.load('id');
     
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
    if (contentControls.items.length === 0) {
        console.log('No content control found.');
    }
    else {
        // Queue a command to put OOXML into the contents of the first content control.
        contentControls.items[0].insertOoxml("<pkg:package xmlns:pkg='http://schemas.microsoft.com/office/2006/xmlPackage'><pkg:part pkg:name='/_rels/.rels' pkg:contentType='application/vnd.openxmlformats-package.relationships+xml' pkg:padding='512'><pkg:xmlData><Relationships xmlns='http://schemas.openxmlformats.org/package/2006/relationships'><Relationship Id='rId1' Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument' Target='word/document.xml'/></Relationships></pkg:xmlData></pkg:part><pkg:part pkg:name='/word/document.xml' pkg:contentType='application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'><pkg:xmlData><w:document xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' ><w:body><w:p><w:pPr><w:spacing w:before='360' w:after='0' w:line='480' w:lineRule='auto'/><w:rPr><w:color w:val='70AD47' w:themeColor='accent6'/><w:sz w:val='28'/></w:rPr></w:pPr><w:r><w:rPr><w:color w:val='70AD47' w:themeColor='accent6'/><w:sz w:val='28'/></w:rPr><w:t>This text has formatting directly applied to achieve its font size, color, line spacing, and paragraph spacing.</w:t></w:r></w:p></w:body></w:document></pkg:xmlData></pkg:part></pkg:package>", "End");
    
        // Synchronize the document state by executing the queued commands, 
        // and return a promise to indicate task completion.
        await context.sync();
        console.log('Inserted OOXML in the first content control.');
    }
});  

// Read "Create better add-ins for Word with Office Open XML" for guidance on working with OOXML.
// https://learn.microsoft.com/office/dev/add-ins/word/create-better-add-ins-for-word-with-office-open-xml

insertParagraph(paragraphText, insertLocation)

Fügt an der angegebenen Position einen Absatz ein.

insertParagraph(paragraphText: string, insertLocation: Word.InsertLocation.start | Word.InsertLocation.end | Word.InsertLocation.before | Word.InsertLocation.after | "Start" | "End" | "Before" | "After"): Word.Paragraph;

Parameter

paragraphText

string

Erforderlich. Der einzufügende Absatztext.

insertLocation

start | end | before | after | "Start" | "End" | "Before" | "After"

Erforderlich. Der Wert muss "Start", "End", "Before" oder "After" sein. "Before" und "After" können nicht mit den Inhaltssteuerelementen "RichTextTable", "RichTextTableRow" und "RichTextTableCell" verwendet werden.

Gibt zurück

Hinweise

[ API-Satz: WordApi 1.1 ]

Beispiele

// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Create a proxy object for the content controls collection.
    const contentControls = context.document.contentControls;
    
    // Queue a command to load the id property for all of the content controls.
    contentControls.load('id');
     
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
    if (contentControls.items.length === 0) {
        console.log('No content control found.');
    }
    else {
        // Queue a command to insert a paragraph after the first content control.
        contentControls.items[0].insertParagraph('Text of the inserted paragraph.', 'After');
    
        // Synchronize the document state by executing the queued commands, 
        // and return a promise to indicate task completion.
        await context.sync();
        console.log('Inserted a paragraph after the first content control.');
    }
});  

insertText(text, insertLocation)

Fügt an der angegebenen Position Text in das Inhaltssteuerelement ein.

insertText(text: string, insertLocation: Word.InsertLocation.replace | Word.InsertLocation.start | Word.InsertLocation.end | "Replace" | "Start" | "End"): Word.Range;

Parameter

text

string

Erforderlich. Der in das Inhaltssteuerelement einzufügende Text.

insertLocation

replace | start | end | "Replace" | "Start" | "End"

Erforderlich. Der Wert muss "Replace", "Start" oder "End" sein. "Replace" kann nicht mit den Inhaltssteuerelementen "RichTextTable" und "RichTextTableRow" verwendet werden.

Gibt zurück

Hinweise

[ API-Satz: WordApi 1.1 ]

Beispiele

// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Create a proxy object for the content controls collection.
    const contentControls = context.document.contentControls;
    
    // Queue a command to load the id property for all of the content controls.
    contentControls.load('id');
     
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
    if (contentControls.items.length === 0) {
        console.log('No content control found.');
    }
    else {
        // Queue a command to replace text in the first content control.
        contentControls.items[0].insertText('Replaced text in the first content control.', 'Replace');
    
        // Synchronize the document state by executing the queued commands, 
        // and return a promise to indicate task completion.
        await context.sync();
        console.log('Replaced text in the first content control.');
    }
});  

// The Silly stories add-in sample shows how to use the insertText method.
// https://aka.ms/sillystorywordaddin

load(options)

Stellt einen Befehl zum Laden der angegebenen Eigenschaften des Objekts in die Warteschlange ein. Vor dem Lesen der Eigenschaften müssen Sie "context.sync()" aufrufen.

load(options?: Word.Interfaces.ContentControlLoadOptions): Word.ContentControl;

Parameter

options
Word.Interfaces.ContentControlLoadOptions

Stellt Optionen dafür bereit, welche Eigenschaften des -Objekts geladen werden sollen.

Gibt zurück

Beispiele

// Load all of the content control properties
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Create a proxy object for the content controls collection.
    const contentControls = context.document.contentControls;
    
    // Queue a command to load the id property for all of the content controls.
    contentControls.load('id');
     
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
    if (contentControls.items.length === 0) {
        console.log('No content control found.');
    } else {
        // Queue a command to load the properties on the first content control.
        contentControls.items[0].load(  'appearance,' +
                                        'cannotDelete,' +
                                        'cannotEdit,' +
                                        'id,' +
                                        'placeHolderText,' +
                                        'removeWhenEdited,' +
                                        'title,' +
                                        'text,' +
                                        'type,' +
                                        'style,' +
                                        'tag,' +
                                        'font/size,' +
                                        'font/name,' +
                                        'font/color');             
    
        // Synchronize the document state by executing the queued commands, 
        // and return a promise to indicate task completion.
        await context.sync();
        console.log('Property values of the first content control:' + 
            '   ----- appearance: ' + contentControls.items[0].appearance + 
            '   ----- cannotDelete: ' + contentControls.items[0].cannotDelete +
            '   ----- cannotEdit: ' + contentControls.items[0].cannotEdit +
            '   ----- color: ' + contentControls.items[0].color +
            '   ----- id: ' + contentControls.items[0].id +
            '   ----- placeHolderText: ' + contentControls.items[0].placeholderText +
            '   ----- removeWhenEdited: ' + contentControls.items[0].removeWhenEdited +
            '   ----- title: ' + contentControls.items[0].title +
            '   ----- text: ' + contentControls.items[0].text +
            '   ----- type: ' + contentControls.items[0].type +
            '   ----- style: ' + contentControls.items[0].style +
            '   ----- tag: ' + contentControls.items[0].tag +
            '   ----- font size: ' + contentControls.items[0].font.size +
            '   ----- font name: ' + contentControls.items[0].font.name +
            '   ----- font color: ' + contentControls.items[0].font.color);
    }
});  

load(propertyNames)

Stellt einen Befehl zum Laden der angegebenen Eigenschaften des Objekts in die Warteschlange ein. Vor dem Lesen der Eigenschaften müssen Sie "context.sync()" aufrufen.

load(propertyNames?: string | string[]): Word.ContentControl;

Parameter

propertyNames

string | string[]

Eine durch Trennzeichen getrennte Zeichenfolge oder ein Array von Zeichenfolgen, die die zu ladenden Eigenschaften angeben.

Gibt zurück

load(propertyNamesAndPaths)

Stellt einen Befehl zum Laden der angegebenen Eigenschaften des Objekts in die Warteschlange ein. Vor dem Lesen der Eigenschaften müssen Sie "context.sync()" aufrufen.

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Word.ContentControl;

Parameter

propertyNamesAndPaths

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

propertyNamesAndPaths.select ist eine durch Trennzeichen getrennte Zeichenfolge, die die zu ladenden Eigenschaften angibt, und propertyNamesAndPaths.expand eine durch Trennzeichen getrennte Zeichenfolge, die die zu ladenden Navigationseigenschaften angibt.

Gibt zurück

search(searchText, searchOptions)

Führt eine Suche mit den angegebenen SearchOptions für den Bereich des Inhaltssteuerelementobjekts aus. Die Suchergebnisse sind eine Sammlung von Bereichsobjekten.

search(searchText: string, searchOptions?: Word.SearchOptions | {
            ignorePunct?: boolean;
            ignoreSpace?: boolean;
            matchCase?: boolean;
            matchPrefix?: boolean;
            matchSuffix?: boolean;
            matchWholeWord?: boolean;
            matchWildcards?: boolean;
        }): Word.RangeCollection;

Parameter

searchText

string

Erforderlich. Der Suchtext.

searchOptions

Word.SearchOptions | { ignorePunct?: boolean; ignoreSpace?: boolean; matchCase?: boolean; matchPrefix?: boolean; matchSuffix?: boolean; matchWholeWord?: boolean; matchWildcards?: boolean; }

Optional. Optionen für die Suche.

Gibt zurück

Hinweise

[ API-Satz: WordApi 1.1 ]

Beispiele

// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Create a proxy object for the content controls collection.
    const contentControls = context.document.contentControls;
    
    // Queue a command to load the id property for all of the content controls.
    contentControls.load('id');
     
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
    if (contentControls.items.length === 0) {
        console.log('No content control found.');
    }
    else {
        // Queue a command to select the first content control.
        contentControls.items[0].select();
    
        // Synchronize the document state by executing the queued commands, 
        // and return a promise to indicate task completion.
        await context.sync();
        console.log('Selected the first content control.');
    }
});  

select(selectionMode)

Wählt das Inhaltssteuerelement aus. Dies bewirkt, dass Word einen Bildlauf zur Auswahl durchführt.

select(selectionMode?: Word.SelectionMode): void;

Parameter

selectionMode
Word.SelectionMode

Optional. Der Auswahlmodus muss "Select", "Start" oder "End" sein. „Select“ ist die Standardeinstellung.

Gibt zurück

void

Hinweise

[ API-Satz: WordApi 1.1 ]

select(selectionModeString)

Wählt das Inhaltssteuerelement aus. Dies bewirkt, dass Word einen Bildlauf zur Auswahl durchführt.

select(selectionModeString?: "Select" | "Start" | "End"): void;

Parameter

selectionModeString

"Select" | "Start" | "End"

Optional. Der Auswahlmodus muss "Select", "Start" oder "End" sein. „Select“ ist die Standardeinstellung.

Gibt zurück

void

Hinweise

[ API-Satz: WordApi 1.1 ]

set(properties, options)

Legt mehrere Eigenschaften eines Objekts gleichzeitig fest. Sie können entweder ein einfaches Objekt mit den entsprechenden Eigenschaften oder ein anderes API-Objekt desselben Typs übergeben.

set(properties: Interfaces.ContentControlUpdateData, options?: OfficeExtension.UpdateOptions): void;

Parameter

properties
Word.Interfaces.ContentControlUpdateData

Ein JavaScript-Objekt mit Eigenschaften, die isomorph zu den Eigenschaften des Objekts strukturiert sind, für das die Methode aufgerufen wird.

options
OfficeExtension.UpdateOptions

Stellt eine Option zum Unterdrücken von Fehlern bereit, wenn das Eigenschaftenobjekt versucht, schreibgeschützte Eigenschaften festzulegen.

Gibt zurück

void

Beispiele

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/10-content-controls/insert-and-change-content-controls.yaml

// Adds title and colors to odd and even content controls and changes their appearance.
await Word.run(async (context) => {
  // Get the complete sentence (as range) associated with the insertion point.
  let evenContentControls = context.document.contentControls.getByTag("even");
  let oddContentControls = context.document.contentControls.getByTag("odd");
  evenContentControls.load("length");
  oddContentControls.load("length");

  await context.sync();

  for (let i = 0; i < evenContentControls.items.length; i++) {
    // Change a few properties and append a paragraph
    evenContentControls.items[i].set({
      color: "red",
      title: "Odd ContentControl #" + (i + 1),
      appearance: Word.ContentControlAppearance.tags
    });
    evenContentControls.items[i].insertParagraph("This is an odd content control", "End");
  }

  for (let j = 0; j < oddContentControls.items.length; j++) {
    // Change a few properties and append a paragraph
    oddContentControls.items[j].set({
      color: "green",
      title: "Even ContentControl #" + (j + 1),
      appearance: "Tags"
    });
    oddContentControls.items[j].insertHtml("This is an <b>even</b> content control", "End");
  }

  await context.sync();
});

set(properties)

Legt mehrere Eigenschaften für das -Objekt gleichzeitig fest, basierend auf einem vorhandenen geladenen Objekt.

set(properties: Word.ContentControl): void;

Parameter

properties
Word.ContentControl

Gibt zurück

void

toJSON()

Überschreibt die JavaScript-Methode toJSON() , um eine nützlichere Ausgabe bereitzustellen, wenn ein API-Objekt an JSON.stringify()übergeben wird. (JSON.stringifyruft wiederum die toJSON -Methode des Objekts auf, das an das Objekt übergeben wird.) Die ursprüngliche Word. ContentControl-Objekt ist ein API-Objekt, die toJSON Methode gibt ein einfaches JavaScript-Objekt (typisiert als Word.Interfaces.ContentControlData) zurück, das flache Kopien aller geladenen untergeordneten Eigenschaften aus dem ursprünglichen Objekt enthält.

toJSON(): Word.Interfaces.ContentControlData;

Gibt zurück

track()

Nachverfolgung des Objekts zwecks automatischer Anpassung auf der Grundlage der umgebenden Änderungen im Dokument. Dieser Aufruf ist eine Kurzform für context.trackedObjects.add(thisObject). Wenn Sie dieses Objekt über .sync Aufrufe hinweg und außerhalb der sequenziellen Ausführung eines ".run"-Batches verwenden und beim Festlegen einer Eigenschaft oder beim Aufrufen einer Methode für das Objekt den Fehler "InvalidObjectPath" erhalten, müssen Sie das Objekt der nachverfolgten Objektauflistung hinzufügen, als das Objekt zum ersten Mal erstellt wurde. Wenn dieses Objekt Teil einer Auflistung ist, sollten Sie auch die übergeordnete Auflistung nachverfolgen.

track(): Word.ContentControl;

Gibt zurück

untrack()

Gibt den diesem Objekt zugewiesenen Arbeitsspeicher frei, wenn das Objekt zuvor nachverfolgt wurde. Dieser Aufruf ist die Kurzform für context.trackedObjects.remove(thisObject). Viele nachverfolgte Objekte verlangsamen die Ausführung der Hostanwendung, also achten Sie darauf, alle hinzugefügten Objekte nach abgeschlossener Verwendung freizugeben. Sie müssen aufrufen context.sync() , bevor die Speicherfreigabe wirksam wird.

untrack(): Word.ContentControl;

Gibt zurück