OneNote.Paragraph class

页面上可见内容的容器。 一个 Paragraph 可包含任意一个 ParagraphType 类型的内容。

扩展

属性

context

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

id

获取段落对象的 ID。

image

获取 Paragraph 中的 Image 对象。 如果 ParagraphType 不是 Image,则引发异常。

inkWords

获取 Paragraph 中的 Ink 集合。 如果 ParagraphType 不为 Ink,则引发异常。

outline

获取包含“段落”的“边框”对象。

paragraphs

此段落下的段落集合。

parentParagraph

获取父段落对象。 如果父段落不存在,则引发。

parentParagraphOrNull

获取父段落对象。 如果父段落不存在,则返回 null。

parentTableCell

获取包含 Paragraph 的 TableCell 对象(如果存在)。 如果父级不是 TableCell,则引发 ItemNotFound。

parentTableCellOrNull

获取包含 Paragraph 的 TableCell 对象(如果存在)。 如果parent不是TableCell,则返回null。

richText

获取 Paragraph 中的 RichText 对象。 如果 ParagraphType 不为 RichText,则引发异常。 只读

table

获取 Paragraph 中的 Table 对象。 如果 ParagraphType 不是 Table,则引发异常。

type

获取 Paragraph 对象的类型。

方法

addNoteTag(type, status)

向段落添加 NoteTag。

addNoteTag(type, status)

向段落添加 NoteTag。

delete()

删除 paragraph

getParagraphInfo()

获取段落的列表信息

insertHtmlAsSibling(insertLocation, html)

插入指定的 HTML 内容

insertHtmlAsSibling(insertLocation, html)

插入指定的 HTML 内容

insertImageAsSibling(insertLocation, base64EncodedImage, width, height)

在指定的插入位置插入图像。

insertImageAsSibling(insertLocation, base64EncodedImage, width, height)

在指定的插入位置插入图像。

insertRichTextAsSibling(insertLocation, paragraphText)

在指定的插入位置插入段落文本。

insertRichTextAsSibling(insertLocation, paragraphText)

在指定的插入位置插入段落文本。

insertTableAsSibling(insertLocation, rowCount, columnCount, values)

将具有指定行数和列数的表格添加到当前段落的之前或之后。

insertTableAsSibling(insertLocation, rowCount, columnCount, values)

将具有指定行数和列数的表格添加到当前段落的之前或之后。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

set(properties, options)

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

set(properties)

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

toJSON()

覆盖 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 (JSON.stringify反过来调用 toJSON 传递给它的对象的方法。) 虽然原始 OneNote.Paragraph 对象是 API 对象, toJSON 但该方法返回一个纯 JavaScript 对象, (类型化为 OneNote.Interfaces.ParagraphData) ,其中包含从原始对象加载的任何子属性的浅层副本。

track()

根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 context.trackedObjects.add (thisObject) 的简写。 如果在调用中 .sync 使用此对象,并且在“.run”批处理的顺序执行之外使用此对象,并且在设置属性或对对象调用方法时收到“InvalidObjectPath”错误,则需要在首次创建对象时将对象添加到跟踪对象集合。

untrack()

释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 context.trackedObjects.remove (thisObject) 的简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 需要在内存释放生效之前调用 context.sync()

属性详细信息

context

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

context: RequestContext;

属性值

id

获取段落对象的 ID。

readonly id: string;

属性值

string

注解

API 集:OneNoteApi 1.1

image

获取 Paragraph 中的 Image 对象。 如果 ParagraphType 不是 Image,则引发异常。

readonly image: OneNote.Image;

属性值

注解

API 集:OneNoteApi 1.1

inkWords

获取 Paragraph 中的 Ink 集合。 如果 ParagraphType 不为 Ink,则引发异常。

readonly inkWords: OneNote.InkWordCollection;

属性值

注解

API 集:OneNoteApi 1.1

outline

获取包含“段落”的“边框”对象。

readonly outline: OneNote.Outline;

属性值

注解

API 集:OneNoteApi 1.1

paragraphs

此段落下的段落集合。

readonly paragraphs: OneNote.ParagraphCollection;

属性值

注解

API 集:OneNoteApi 1.1

parentParagraph

获取父段落对象。 如果父段落不存在,则引发。

readonly parentParagraph: OneNote.Paragraph;

属性值

注解

API 集:OneNoteApi 1.1

parentParagraphOrNull

获取父段落对象。 如果父段落不存在,则返回 null。

readonly parentParagraphOrNull: OneNote.Paragraph;

属性值

注解

API 集:OneNoteApi 1.1

parentTableCell

获取包含 Paragraph 的 TableCell 对象(如果存在)。 如果父级不是 TableCell,则引发 ItemNotFound。

readonly parentTableCell: OneNote.TableCell;

属性值

注解

API 集:OneNoteApi 1.1

parentTableCellOrNull

获取包含 Paragraph 的 TableCell 对象(如果存在)。 如果parent不是TableCell,则返回null。

readonly parentTableCellOrNull: OneNote.TableCell;

属性值

注解

API 集:OneNoteApi 1.1

richText

获取 Paragraph 中的 RichText 对象。 如果 ParagraphType 不为 RichText,则引发异常。 只读

readonly richText: OneNote.RichText;

属性值

注解

API 集:OneNoteApi 1.1

table

获取 Paragraph 中的 Table 对象。 如果 ParagraphType 不是 Table,则引发异常。

readonly table: OneNote.Table;

属性值

注解

API 集:OneNoteApi 1.1

type

获取 Paragraph 对象的类型。

readonly type: OneNote.ParagraphType | "RichText" | "Image" | "Table" | "Ink" | "Other";

属性值

OneNote.ParagraphType | "RichText" | "Image" | "Table" | "Ink" | "Other"

注解

API 集:OneNoteApi 1.1

方法详细信息

addNoteTag(type, status)

向段落添加 NoteTag。

addNoteTag(type: OneNote.NoteTagType, status: OneNote.NoteTagStatus): OneNote.NoteTag;

参数

type
OneNote.NoteTagType

NoteTag 的类型。

status
OneNote.NoteTagStatus

NoteTag 的状态。

返回

注解

API 集:OneNoteApi 1.1

addNoteTag(type, status)

向段落添加 NoteTag。

addNoteTag(type: "Unknown" | "ToDo" | "Important" | "Question" | "Contact" | "Address" | "PhoneNumber" | "Website" | "Idea" | "Critical" | "ToDoPriority1" | "ToDoPriority2", status: "Unknown" | "Normal" | "Completed" | "Disabled" | "OutlookTask" | "TaskNotSyncedYet" | "TaskRemoved"): OneNote.NoteTag;

参数

type

"Unknown" | "ToDo" | "Important" | "Question" | "Contact" | "Address" | "PhoneNumber" | "Website" | "Idea" | "Critical" | "ToDoPriority1" | "ToDoPriority2"

NoteTag 的类型。

status

"Unknown" | "Normal" | "Completed" | "Disabled" | "OutlookTask" | "TaskNotSyncedYet" | "TaskRemoved"

NoteTag 的状态。

返回

注解

API 集:OneNoteApi 1.1

delete()

删除 paragraph

delete(): void;

返回

void

注解

API 集:OneNoteApi 1.1

示例

await OneNote.run(async (context) => {

    // Get the collection of pageContent items from the page.
    const pageContents = context.application.getActivePage().contents;

    // Get the first PageContent on the page assuming its an outline, get the outline's paragraphs.
    const pageContent = pageContents.getItemAt(0);
    
    const paragraphs = pageContent.outline.paragraphs;
    
    const firstParagraph = paragraphs.getItemAt(0);
    
    // Queue a command to load the id and type of the first paragraph.
    firstParagraph.load("id,type");

    // Run the queued commands, and return a promise to indicate task completion.
    await context.sync();
            
    // Queue a command to delete the first paragraph.
    firstParagraph.delete();
    
    // Run the command to delete it.
    await context.sync();
});

getParagraphInfo()

获取段落的列表信息

getParagraphInfo(): OfficeExtension.ClientResult<OneNote.ParagraphInfo>;

返回

注解

API 集:OneNoteApi 1.1

insertHtmlAsSibling(insertLocation, html)

插入指定的 HTML 内容

insertHtmlAsSibling(insertLocation: OneNote.InsertLocation, html: string): void;

参数

insertLocation
OneNote.InsertLocation

相对于当前 Paragraph 的新内容的位置。

html

string

描述内容的可视化演示文稿的 HTML 字符串。 请参阅 OneNote 加载项 JavaScript API 支持的 HTML

返回

void

注解

API 集:OneNoteApi 1.1

示例

await OneNote.run(async (context) => {

    // Get the collection of pageContent items from the page.
    const pageContents = context.application.getActivePage().contents;

    // Get the first PageContent on the page.
    // Assuming its an outline, get the outline's paragraphs.
    const pageContent = pageContents.getItemAt(0);
    const paragraphs = pageContent.outline.paragraphs;
    const firstParagraph = paragraphs.getItemAt(0);

    // Queue a command to load the id and type of the first paragraph.
    firstParagraph.load("id,type");

    // Run the queued commands, and return a promise to indicate task completion.
    await context.sync();

    // Queue commands to insert before and after the first paragraph.
    firstParagraph.insertHtmlAsSibling("Before", "<p>ContentBeforeFirstParagraph</p>");
    firstParagraph.insertHtmlAsSibling("After", "<p>ContentAfterFirstParagraph</p>");
    
    // Run the command to run inserts.
    await context.sync();
});

insertHtmlAsSibling(insertLocation, html)

插入指定的 HTML 内容

insertHtmlAsSibling(insertLocation: "Before" | "After", html: string): void;

参数

insertLocation

"Before" | "After"

相对于当前 Paragraph 的新内容的位置。

html

string

描述内容的可视化演示文稿的 HTML 字符串。 请参阅 OneNote 加载项 JavaScript API 支持的 HTML

返回

void

注解

API 集:OneNoteApi 1.1

insertImageAsSibling(insertLocation, base64EncodedImage, width, height)

在指定的插入位置插入图像。

insertImageAsSibling(insertLocation: OneNote.InsertLocation, base64EncodedImage: string, width: number, height: number): OneNote.Image;

参数

insertLocation
OneNote.InsertLocation

相对于当前段落的表格的位置。

base64EncodedImage

string

要追加的 HTML 字符串。

width

number

可选。 以磅为单位的宽度。 默认值为 null,将考虑图像宽度。

height

number

可选。 以磅为单位的高度。 默认值为 null,将考虑图像高度。

返回

注解

API 集:OneNoteApi 1.1

示例

await OneNote.run(async (context) => {

    // Get the collection of pageContent items from the page.
    const pageContents = context.application.getActivePage().contents;

    // Get the first PageContent on the page.
    // Assuming its an outline, get the outline's paragraphs.
    const pageContent = pageContents.getItemAt(0);
    const paragraphs = pageContent.outline.paragraphs;
    const firstParagraph = paragraphs.getItemAt(0);

    // Queue a command to load the id and type of the first paragraph.
    firstParagraph.load("id,type");

    // Run the queued commands, and return a promise to indicate task completion.
    await context.sync();

    // Queue commands to insert before and after the first paragraph.
    firstParagraph.insertImageAsSibling("Before", "R0lGODlhDwAPAKECAAAAzMzM/////wAAACwAAAAADwAPAAACIISPeQHsrZ5ModrLlN48CXF8m2iQ3YmmKqVlRtW4MLwWACH+H09wdGltaXplZCBieSBVbGVhZCBTbWFydFNhdmVyIQAAOw==");
    firstParagraph.insertImageAsSibling("After", "R0lGODlhDwAPAKECAAAAzMzM/////wAAACwAAAAADwAPAAACIISPeQHsrZ5ModrLlN48CXF8m2iQ3YmmKqVlRtW4MLwWACH+H09wdGltaXplZCBieSBVbGVhZCBTbWFydFNhdmVyIQAAOw==");
    
    // Run the command to insert images.
    await context.sync();
});

insertImageAsSibling(insertLocation, base64EncodedImage, width, height)

在指定的插入位置插入图像。

insertImageAsSibling(insertLocation: "Before" | "After", base64EncodedImage: string, width: number, height: number): OneNote.Image;

参数

insertLocation

"Before" | "After"

相对于当前段落的表格的位置。

base64EncodedImage

string

要追加的 HTML 字符串。

width

number

可选。 以磅为单位的宽度。 默认值为 null,将考虑图像宽度。

height

number

可选。 以磅为单位的高度。 默认值为 null,将考虑图像高度。

返回

注解

API 集:OneNoteApi 1.1

insertRichTextAsSibling(insertLocation, paragraphText)

在指定的插入位置插入段落文本。

insertRichTextAsSibling(insertLocation: OneNote.InsertLocation, paragraphText: string): OneNote.RichText;

参数

insertLocation
OneNote.InsertLocation

相对于当前段落的表格的位置。

paragraphText

string

要追加的 HTML 字符串。

返回

注解

API 集:OneNoteApi 1.1

示例

await OneNote.run(async (context) => {

    // Get the collection of pageContent items from the page.
    const pageContents = context.application.getActivePage().contents;

    // Get the first PageContent on the page assuming its an outline, get the outline's paragraphs.
    const pageContent = pageContents.getItemAt(0);
    const paragraphs = pageContent.outline.paragraphs;
    const firstParagraph = paragraphs.getItemAt(0);

    // Queue a command to load the id and type of the first paragraph.
    firstParagraph.load("id,type");

    // Run the queued commands, and return a promise to indicate task completion.
    await context.sync();

    // Queue commands to insert before and after the first paragraph.
    firstParagraph.insertRichTextAsSibling("Before", "Text Appears Before Paragraph");
    firstParagraph.insertRichTextAsSibling("After", "Text Appears After Paragraph");
    
    // Run the command to insert text contents.
    await context.sync();
});

insertRichTextAsSibling(insertLocation, paragraphText)

在指定的插入位置插入段落文本。

insertRichTextAsSibling(insertLocation: "Before" | "After", paragraphText: string): OneNote.RichText;

参数

insertLocation

"Before" | "After"

相对于当前段落的表格的位置。

paragraphText

string

要追加的 HTML 字符串。

返回

注解

API 集:OneNoteApi 1.1

insertTableAsSibling(insertLocation, rowCount, columnCount, values)

将具有指定行数和列数的表格添加到当前段落的之前或之后。

insertTableAsSibling(insertLocation: OneNote.InsertLocation, rowCount: number, columnCount: number, values?: string[][]): OneNote.Table;

参数

insertLocation
OneNote.InsertLocation

相对于当前段落的表格的位置。

rowCount

number

表格的行数。

columnCount

number

表格的列数。

values

string[][]

可选的二维数组。 如果指定数组中的对应字符串,则填充单元格。

返回

注解

API 集:OneNoteApi 1.1

insertTableAsSibling(insertLocation, rowCount, columnCount, values)

将具有指定行数和列数的表格添加到当前段落的之前或之后。

insertTableAsSibling(insertLocation: "Before" | "After", rowCount: number, columnCount: number, values?: string[][]): OneNote.Table;

参数

insertLocation

"Before" | "After"

相对于当前段落的表格的位置。

rowCount

number

表格的行数。

columnCount

number

表格的列数。

values

string[][]

可选的二维数组。 如果指定数组中的对应字符串,则填充单元格。

返回

注解

API 集:OneNoteApi 1.1

load(options)

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

load(options?: OneNote.Interfaces.ParagraphLoadOptions): OneNote.Paragraph;

参数

options
OneNote.Interfaces.ParagraphLoadOptions

为要加载的对象属性提供选项。

返回

load(propertyNames)

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

load(propertyNames?: string | string[]): OneNote.Paragraph;

参数

propertyNames

string | string[]

指定要加载的属性的逗号分隔的字符串或字符串数组。

返回

示例

await OneNote.run(async (context) => {

    // Get the collection of pageContent items from the page.
    const pageContents = context.application.getActivePage().contents;
    
    // Queue a command to load the outline property of each pageContent.
    pageContents.load("outline");
        
    // Get the first PageContent on the page, and then get its Outline.
    const pageContent = pageContents._GetItem(0);
    const paragraphs = pageContent.outline.paragraphs;
            
    // Queue a command to load the id and type of each paragraph.
    paragraphs.load("id,type");
            
    // Run the queued commands, and return a promise to indicate task completion.
    await context.sync();
    // Write the text.
    $.each(paragraphs.items, function(index, paragraph) {
        console.log("Paragraph type: " + paragraph.type);
        console.log("Paragraph ID: " + paragraph.id);
    });
});

load(propertyNamesAndPaths)

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

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): OneNote.Paragraph;

参数

propertyNamesAndPaths

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

propertyNamesAndPaths.select 是指定要加载的属性的逗号分隔字符串,以及 propertyNamesAndPaths.expand 指定要加载的导航属性的逗号分隔字符串。

返回

set(properties, options)

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

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

参数

properties
OneNote.Interfaces.ParagraphUpdateData

一个 JavaScript 对象,其属性与调用该方法的对象的属性同构结构。

options
OfficeExtension.UpdateOptions

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

返回

void

set(properties)

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

set(properties: OneNote.Paragraph): void;

参数

properties
OneNote.Paragraph

返回

void

toJSON()

覆盖 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 (JSON.stringify反过来调用 toJSON 传递给它的对象的方法。) 虽然原始 OneNote.Paragraph 对象是 API 对象, toJSON 但该方法返回一个纯 JavaScript 对象, (类型化为 OneNote.Interfaces.ParagraphData) ,其中包含从原始对象加载的任何子属性的浅层副本。

toJSON(): OneNote.Interfaces.ParagraphData;

返回

track()

根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 context.trackedObjects.add (thisObject) 的简写。 如果在调用中 .sync 使用此对象,并且在“.run”批处理的顺序执行之外使用此对象,并且在设置属性或对对象调用方法时收到“InvalidObjectPath”错误,则需要在首次创建对象时将对象添加到跟踪对象集合。

track(): OneNote.Paragraph;

返回

untrack()

释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 context.trackedObjects.remove (thisObject) 的简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 需要在内存释放生效之前调用 context.sync()

untrack(): OneNote.Paragraph;

返回