OneNote.Paragraph class

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

Extends

注解

[ API 集:OneNoteApi 1.1 ]

属性

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 对象(如果存在)。 如果父级不为 TableCell,则返回 null。 只读。

richText

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

table

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

type

获取 Paragraph 对象的类型。 只读。

方法

addNoteTag(type, status)

将 NoteTag 添加到段落。

addNoteTag(typeString, statusString)

将 NoteTag 添加到段落。

delete()

删除 paragraph

getParagraphInfo()

获取段落的列表信息

insertHtmlAsSibling(insertLocation, html)

插入指定的 HTML 内容

insertHtmlAsSibling(insertLocationString, html)

插入指定的 HTML 内容

insertImageAsSibling(insertLocation, base64EncodedImage, width, height)

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

insertImageAsSibling(insertLocationString, base64EncodedImage, width, height)

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

insertRichTextAsSibling(insertLocation, paragraphText)

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

insertRichTextAsSibling(insertLocationString, paragraphText)

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

insertTableAsSibling(insertLocation, rowCount, columnCount, values)

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

insertTableAsSibling(insertLocationString, 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 对象(如果存在)。 如果父级不为 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(typeString, statusString)

将 NoteTag 添加到段落。

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

参数

typeString

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

NoteTag 的类型。

statusString

"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(insertLocationString, html)

插入指定的 HTML 内容

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

参数

insertLocationString

"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(insertLocationString, base64EncodedImage, width, height)

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

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

参数

insertLocationString

"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(insertLocationString, paragraphText)

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

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

参数

insertLocationString

"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(insertLocationString, rowCount, columnCount, values)

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

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

参数

insertLocationString

"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;

返回