Word.SearchOptions class

検索操作に含めるオプションを指定します。 Word JavaScript API で検索オプションを使用する方法の詳細については、「検索オプションを使用して Word アドインでテキストを検索する」を参照してください

Extends

注釈

API セット: WordApi 1.1

使用元

// Search using a wildcard
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Queue a command to search the document with a wildcard
    // for any string of characters that starts with 'to' and ends with 'n'.
    const searchResults = context.document.body.search('to*n', {matchWildcards: true});

    // Queue a command to load the search results and get the font property values.
    searchResults.load('font');
    
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Found count: ' + searchResults.items.length);

    // Queue a set of commands to change the font for each found item.
    for (let i = 0; i < searchResults.items.length; i++) {
        searchResults.items[i].font.color = 'purple';
        searchResults.items[i].font.highlightColor = 'pink';
        searchResults.items[i].font.bold = true;
    }
    
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
}); 

プロパティ

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

ignorePunct

指定された場合は、単語間の句読点文字をすべて無視するかどうかを指定します。 既定値は false です。 [検索と置換] ダイアログ ボックスの [_Ignore句読点characters_ チェック] ボックスに対応します。

ignoreSpace

指定した場合、単語間の空白をすべて無視するかどうかを指定します。 既定値は false です。 [検索と置換] ダイアログ ボックスの_Ignore空白characters_ チェックボックスに対応します。

matchCase

指定した場合は、大文字と小文字を区別する検索を実行するかどうかを指定します。 既定値は false です。 [検索と置換] ダイアログ ボックスの [_Match case_ チェック] ボックスに対応します。

matchPrefix

指定した場合、検索文字列で始まる単語と一致させるかどうかを指定します。 既定値は false です。 [検索と置換] ダイアログ ボックスの [_Match prefix_ チェック] ボックスに対応します。

matchSuffix

指定した場合、検索文字列で終わる単語を一致させるかどうかを指定します。 既定値は false です。 [検索と置換] ダイアログ ボックスの [_Match suffix_ チェック] ボックスに対応します。

matchWholeWord

指定した場合、より大きな単語の一部であるテキストではなく、単語全体のみを検索するかどうかを指定します。 既定値は false です。 [検索と置換] ダイアログ ボックスの [単語全体only_ チェック] ボックス_Findに対応します。

matchWildcards

指定した場合は、特別な検索演算子を使用して検索を実行するかどうかを指定します。 既定値は false です。 [検索と置換] ダイアログ ボックスの [_Use wildcards_ チェック] ボックスに対応します。

メソッド

load(options)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNames)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNamesAndPaths)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

newObject(context)

Word.SearchOptions オブジェクトの新しいインスタンスを作成します。

set(properties, options)

オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクト、または同じ型の別の API オブジェクトを渡すことができます。

set(properties)

既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。

toJSON()

API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の Word.SearchOptions オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、元のオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト ( Word.Interfaces.SearchOptionsData と型指定) を返します。

プロパティの詳細

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

context: RequestContext;

プロパティ値

ignorePunct

指定された場合は、単語間の句読点文字をすべて無視するかどうかを指定します。 既定値は false です。 [検索と置換] ダイアログ ボックスの [_Ignore句読点characters_ チェック] ボックスに対応します。

ignorePunct: boolean;

プロパティ値

boolean

注釈

API セット: WordApi 1.1

ignoreSpace

指定した場合、単語間の空白をすべて無視するかどうかを指定します。 既定値は false です。 [検索と置換] ダイアログ ボックスの_Ignore空白characters_ チェックボックスに対応します。

ignoreSpace: boolean;

プロパティ値

boolean

注釈

API セット: WordApi 1.1

matchCase

指定した場合は、大文字と小文字を区別する検索を実行するかどうかを指定します。 既定値は false です。 [検索と置換] ダイアログ ボックスの [_Match case_ チェック] ボックスに対応します。

matchCase: boolean;

プロパティ値

boolean

注釈

API セット: WordApi 1.1

matchPrefix

指定した場合、検索文字列で始まる単語と一致させるかどうかを指定します。 既定値は false です。 [検索と置換] ダイアログ ボックスの [_Match prefix_ チェック] ボックスに対応します。

matchPrefix: boolean;

プロパティ値

boolean

注釈

API セット: WordApi 1.1

matchSuffix

指定した場合、検索文字列で終わる単語を一致させるかどうかを指定します。 既定値は false です。 [検索と置換] ダイアログ ボックスの [_Match suffix_ チェック] ボックスに対応します。

matchSuffix: boolean;

プロパティ値

boolean

注釈

API セット: WordApi 1.1

matchWholeWord

指定した場合、より大きな単語の一部であるテキストではなく、単語全体のみを検索するかどうかを指定します。 既定値は false です。 [検索と置換] ダイアログ ボックスの [単語全体only_ チェック] ボックス_Findに対応します。

matchWholeWord: boolean;

プロパティ値

boolean

注釈

API セット: WordApi 1.1

matchWildcards

指定した場合は、特別な検索演算子を使用して検索を実行するかどうかを指定します。 既定値は false です。 [検索と置換] ダイアログ ボックスの [_Use wildcards_ チェック] ボックスに対応します。

matchWildcards: boolean;

プロパティ値

boolean

注釈

API セット: WordApi 1.1

メソッドの詳細

load(options)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(options?: Word.Interfaces.SearchOptionsLoadOptions): Word.SearchOptions;

パラメーター

options
Word.Interfaces.SearchOptionsLoadOptions

読み込むオブジェクトのプロパティのオプションを指定します。

返品

// Ignore punctuation search
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Queue a command to search the document and ignore punctuation.
    const searchResults = context.document.body.search('video you', {ignorePunct: true});

    // Queue a command to load the search results and get the font property values.
    searchResults.load('font');
    
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Found count: ' + searchResults.items.length);

    // Queue a set of commands to change the font for each found item.
    for (let i = 0; i < searchResults.items.length; i++) {
        searchResults.items[i].font.color = 'purple';
        searchResults.items[i].font.highlightColor = '#FFFF00'; //Yellow
        searchResults.items[i].font.bold = true;
    }
    
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
});  
// Search based on a prefix
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Queue a command to search the document based on a prefix.
    const searchResults = context.document.body.search('vid', {matchPrefix: true});

    // Queue a command to load the search results and get the font property values.
    searchResults.load('font');
    
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();

    // Queue a set of commands to change the font for each found item.
    for (let i = 0; i < searchResults.items.length; i++) {
        searchResults.items[i].font.color = 'purple';
        searchResults.items[i].font.highlightColor = '#FFFF00'; //Yellow
        searchResults.items[i].font.bold = true;
    }
    
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
}); 
// Search based on a suffix
// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Queue a command to search the document for any string of characters after 'ly'.
    const searchResults = context.document.body.search('ly', {matchSuffix: true});

    // Queue a command to load the search results and get the font property values.
    searchResults.load('font');
    
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Found count: ' + searchResults.items.length);

    // Queue a set of commands to change the font for each found item.
    for (let i = 0; i < searchResults.items.length; i++) {
        searchResults.items[i].font.color = 'orange';
        searchResults.items[i].font.highlightColor = 'black';
        searchResults.items[i].font.bold = true;
    }
    
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
});  
// Search using a wildcard
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Queue a command to search the document with a wildcard
    // for any string of characters that starts with 'to' and ends with 'n'.
    const searchResults = context.document.body.search('to*n', {matchWildcards: true});

    // Queue a command to load the search results and get the font property values.
    searchResults.load('font');
    
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Found count: ' + searchResults.items.length);

    // Queue a set of commands to change the font for each found item.
    for (let i = 0; i < searchResults.items.length; i++) {
        searchResults.items[i].font.color = 'purple';
        searchResults.items[i].font.highlightColor = 'pink';
        searchResults.items[i].font.bold = true;
    }
    
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
}); 

load(propertyNames)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

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

パラメーター

propertyNames

string | string[]

読み込むプロパティを指定するコンマ区切りの文字列または文字列の配列。

返品

load(propertyNamesAndPaths)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

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

パラメーター

propertyNamesAndPaths

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

propertyNamesAndPaths.select は読み込むプロパティを指定するコンマ区切りの文字列であり、 propertyNamesAndPaths.expand は読み込むナビゲーションのプロパティを指定するコンマ区切りの文字列です。

返品

newObject(context)

Word.SearchOptions オブジェクトの新しいインスタンスを作成します。

static newObject(context: OfficeExtension.ClientRequestContext): Word.SearchOptions;

パラメーター

返品

set(properties, options)

オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクト、または同じ型の別の API オブジェクトを渡すことができます。

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

パラメーター

properties
Word.Interfaces.SearchOptionsUpdateData

メソッドが呼び出されたオブジェクトのプロパティと同型構造のプロパティを持つ JavaScript オブジェクト。

options
OfficeExtension.UpdateOptions

プロパティ オブジェクトが読み取り専用プロパティを設定しようとした場合にエラーを抑制するオプションを提供します。

返品

void

set(properties)

既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。

set(properties: Word.SearchOptions): void;

パラメーター

properties
Word.SearchOptions

返品

void

toJSON()

API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の Word.SearchOptions オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、元のオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト ( Word.Interfaces.SearchOptionsData と型指定) を返します。

toJSON(): Word.Interfaces.SearchOptionsData;

返品