Word.SearchOptions class

指定要包括在搜索操作中的选项。 若要详细了解如何在 Word JavaScript API 中使用搜索选项,请阅读使用搜索选项查找Word加载项中的文本。

Extends

注解

[ API 集:WordApi 1.1 ]

属性

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

ignorePunct

指定一个值,该值指示是否忽略单词之间的所有标点符号。 对应于“查找和替换”对话框中的“忽略标点符号”复选框。

ignoreSpace

指定一个值,该值指示是否忽略单词之间的所有空格。 对应于“查找和替换”对话框中的“忽略空格字符检查框。

matchCase

指定一个值,该值指示是否执行区分大小写的搜索。 对应于“查找和替换”对话框中的“匹配大小写检查框。

matchPrefix

指定一个值,该值指示是否匹配以搜索字符串开头的单词。 对应于“查找和替换”对话框中的“匹配前缀”复选框。

matchSuffix

指定一个值,该值指示是否匹配以搜索字符串结尾的单词。 对应于“查找和替换”对话框中的“匹配后缀”复选框。

matchWholeWord

指定一个值,该值指示是否仅查找操作整个单词,而不查找属于较大单词的文本。 对应于“查找和替换”对话框中的“全字匹配”复选框。

matchWildcards

指定一个值,该值指示是否将使用特殊搜索运算符执行搜索。 对应于“查找和替换”对话框中的“使用通配符”复选框。

方法

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

newObject(context)

创建 Word 的新实例。SearchOptions 对象

set(properties, options)

同时设置对象的多个属性。 可以传递具有相应属性的纯对象,也可以传递同一类型的另一个 API 对象。

set(properties)

基于现有的已加载对象,同时对对象设置多个属性。

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,反过来又调用toJSON传递给它的 对象的 方法。) 而原始Word。SearchOptions 对象是一个 API 对象,toJSON该方法返回一个纯 JavaScript 对象, (类型化为 Word.Interfaces.SearchOptionsData) ,其中包含原始对象中任何已加载子属性的浅表副本。

属性详细信息

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

context: RequestContext;

属性值

ignorePunct

指定一个值,该值指示是否忽略单词之间的所有标点符号。 对应于“查找和替换”对话框中的“忽略标点符号”复选框。

ignorePunct: boolean;

属性值

boolean

注解

[ API 集:WordApi 1.1 ]

ignoreSpace

指定一个值,该值指示是否忽略单词之间的所有空格。 对应于“查找和替换”对话框中的“忽略空格字符检查框。

ignoreSpace: boolean;

属性值

boolean

注解

[ API 集:WordApi 1.1 ]

matchCase

指定一个值,该值指示是否执行区分大小写的搜索。 对应于“查找和替换”对话框中的“匹配大小写检查框。

matchCase: boolean;

属性值

boolean

注解

[ API 集:WordApi 1.1 ]

matchPrefix

指定一个值,该值指示是否匹配以搜索字符串开头的单词。 对应于“查找和替换”对话框中的“匹配前缀”复选框。

matchPrefix: boolean;

属性值

boolean

注解

[ API 集:WordApi 1.1 ]

matchSuffix

指定一个值,该值指示是否匹配以搜索字符串结尾的单词。 对应于“查找和替换”对话框中的“匹配后缀”复选框。

matchSuffix: boolean;

属性值

boolean

注解

[ API 集:WordApi 1.1 ]

matchWholeWord

指定一个值,该值指示是否仅查找操作整个单词,而不查找属于较大单词的文本。 对应于“查找和替换”对话框中的“全字匹配”复选框。

matchWholeWord: boolean;

属性值

boolean

注解

[ API 集:WordApi 1.1 ]

matchWildcards

指定一个值,该值指示是否将使用特殊搜索运算符执行搜索。 对应于“查找和替换”对话框中的“使用通配符”复选框。

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

提供一个选项,用于在 properties 对象尝试设置任何只读属性时禁止显示错误。

返回

void

set(properties)

基于现有的已加载对象,同时对对象设置多个属性。

set(properties: Word.SearchOptions): void;

参数

properties
Word.SearchOptions

返回

void

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,反过来又调用toJSON传递给它的 对象的 方法。) 而原始Word。SearchOptions 对象是一个 API 对象,toJSON该方法返回一个纯 JavaScript 对象, (类型化为 Word.Interfaces.SearchOptionsData) ,其中包含原始对象中任何已加载子属性的浅表副本。

toJSON(): Word.Interfaces.SearchOptionsData;

返回