OneNote.Paragraph class

A container for the visible content on a page. A Paragraph can contain any one ParagraphType type of content.

[ API set: OneNoteApi 1.1 ]

Extends
OfficeExtension.ClientObject

Properties

id

Gets the ID of the Paragraph object. Read-only.

[ API set: OneNoteApi 1.1 ]

image

Gets the Image object in the Paragraph. Throws an exception if ParagraphType is not Image. Read-only.

[ API set: OneNoteApi 1.1 ]

inkWords

Gets the Ink collection in the Paragraph. Throws an exception if ParagraphType is not Ink. Read-only.

[ API set: OneNoteApi 1.1 ]

outline

Gets the Outline object that contains the Paragraph. Read-only.

[ API set: OneNoteApi 1.1 ]

paragraphs

The collection of paragraphs under this paragraph. Read only

[ API set: OneNoteApi 1.1 ]

parentParagraph

Gets the parent paragraph object. Throws if a parent paragraph does not exist. Read-only.

[ API set: OneNoteApi 1.1 ]

parentParagraphOrNull

Gets the parent paragraph object. Returns null if a parent paragraph does not exist. Read-only.

[ API set: OneNoteApi 1.1 ]

parentTableCell

Gets the TableCell object that contains the Paragraph if one exists. If parent is not a TableCell, throws ItemNotFound. Read-only.

[ API set: OneNoteApi 1.1 ]

parentTableCellOrNull

Gets the TableCell object that contains the Paragraph if one exists. If parent is not a TableCell, returns null. Read-only.

[ API set: OneNoteApi 1.1 ]

richText

Gets the RichText object in the Paragraph. Throws an exception if ParagraphType is not RichText. Read-only

[ API set: OneNoteApi 1.1 ]

table

Gets the Table object in the Paragraph. Throws an exception if ParagraphType is not Table. Read-only.

[ API set: OneNoteApi 1.1 ]

type

Gets the type of the Paragraph object. Read-only.

[ API set: OneNoteApi 1.1 ]

Methods

addNoteTag(type, status)

Add NoteTag to the paragraph.

[ API set: OneNoteApi 1.1 ]

delete()

Deletes the paragraph

[ API set: OneNoteApi 1.1 ]

getParagraphInfo()

Get list information of paragraph

[ API set: OneNoteApi 1.1 ]

insertHtmlAsSibling(insertLocation, html)

Inserts the specified HTML content

[ API set: OneNoteApi 1.1 ]

insertImageAsSibling(insertLocation, base64EncodedImage, width, height)

Inserts the image at the specified insert location..

[ API set: OneNoteApi 1.1 ]

insertRichTextAsSibling(insertLocation, paragraphText)

Inserts the paragraph text at the specifiec insert location.

[ API set: OneNoteApi 1.1 ]

insertTableAsSibling(insertLocation, rowCount, columnCount, values)

Adds a table with the specified number of rows and columns before or after the current paragraph.

[ API set: OneNoteApi 1.1 ]

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

toJSON()
track()

Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for context.trackedObjects.add(thisObject). If you are using this object across ".sync" calls and outside the sequential execution of a ".run" batch, and get an "InvalidObjectPath" error when setting a property or invoking a method on the object, you needed to have added the object to the tracked object collection when the object was first created.

untrack()

Release the memory associated with this object, if it has previously been tracked. This call is shorthand for context.trackedObjects.remove(thisObject). Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You will need to call "context.sync()" before the memory release takes effect.

Property Details

id

Gets the ID of the Paragraph object. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly id: string;

Property Value

string

image

Gets the Image object in the Paragraph. Throws an exception if ParagraphType is not Image. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly image: OneNote.Image;

Property Value

inkWords

Gets the Ink collection in the Paragraph. Throws an exception if ParagraphType is not Ink. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly inkWords: OneNote.InkWordCollection;

Property Value

outline

Gets the Outline object that contains the Paragraph. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly outline: OneNote.Outline;

Property Value

paragraphs

The collection of paragraphs under this paragraph. Read only

[ API set: OneNoteApi 1.1 ]

readonly paragraphs: OneNote.ParagraphCollection;

Property Value

parentParagraph

Gets the parent paragraph object. Throws if a parent paragraph does not exist. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly parentParagraph: OneNote.Paragraph;

Property Value

parentParagraphOrNull

Gets the parent paragraph object. Returns null if a parent paragraph does not exist. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly parentParagraphOrNull: OneNote.Paragraph;

Property Value

parentTableCell

Gets the TableCell object that contains the Paragraph if one exists. If parent is not a TableCell, throws ItemNotFound. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly parentTableCell: OneNote.TableCell;

Property Value

parentTableCellOrNull

Gets the TableCell object that contains the Paragraph if one exists. If parent is not a TableCell, returns null. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly parentTableCellOrNull: OneNote.TableCell;

Property Value

richText

Gets the RichText object in the Paragraph. Throws an exception if ParagraphType is not RichText. Read-only

[ API set: OneNoteApi 1.1 ]

readonly richText: OneNote.RichText;

Property Value

table

Gets the Table object in the Paragraph. Throws an exception if ParagraphType is not Table. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly table: OneNote.Table;

Property Value

OneNote.Table

type

Gets the type of the Paragraph object. Read-only.

[ API set: OneNoteApi 1.1 ]

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

Property Value

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

Method Details

addNoteTag(type, status)

Add NoteTag to the paragraph.

[ API set: OneNoteApi 1.1 ]

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

Parameters

type
OneNote.NoteTagType

The type of the NoteTag.

status
OneNote.NoteTagStatus

The status of the NoteTag.

Returns

delete()

Deletes the paragraph

[ API set: OneNoteApi 1.1 ]

delete(): void;

Returns

void

Examples

OneNote.run(function (context) {

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

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

    var paragraphs = pageContent.outline.paragraphs;

    var 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.
    return context.sync()
        .then(function () {

            // Queue a command to delete the first paragraph                 
            firstParagraph.delete();

            // Run the command to delete it
            return context.sync();
        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

getParagraphInfo()

Get list information of paragraph

[ API set: OneNoteApi 1.1 ]

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

Returns

OfficeExtension.ClientResult<OneNote.ParagraphInfo>

insertHtmlAsSibling(insertLocation, html)

Inserts the specified HTML content

[ API set: OneNoteApi 1.1 ]

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

Parameters

insertLocation
OneNote.InsertLocation

The location of new contents relative to the current Paragraph.

html
string

An HTML string that describes the visual presentation of the content. See Supported HTML for the OneNote add-ins JavaScript API.

Returns

void

Examples

OneNote.run(function (context) {

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

    // Get the first PageContent on the page
    // Assuming its an outline, get the outline's paragraphs.
    var pageContent = pageContents.getItemAt(0);
    var paragraphs = pageContent.outline.paragraphs;
    var 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.
    return context.sync()
        .then(function () {

            // 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
            return context.sync();
        });
))
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

insertImageAsSibling(insertLocation, base64EncodedImage, width, height)

Inserts the image at the specified insert location..

[ API set: OneNoteApi 1.1 ]

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

Parameters

insertLocation
OneNote.InsertLocation

The location of the table relative to the current Paragraph.

base64EncodedImage
string

HTML string to append.

width
number

Optional. Width in the unit of Points. The default value is null and image width will be respected.

height
number

Optional. Height in the unit of Points. The default value is null and image height will be respected.

Returns

Examples

OneNote.run(function (context) {

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

    // Get the first PageContent on the page
    // Assuming its an outline, get the outline's paragraphs.
    var pageContent = pageContents.getItemAt(0);
    var paragraphs = pageContent.outline.paragraphs;
    var 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.
    return context.sync()
        .then(function () {

            // 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
            return context.sync();
        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

insertRichTextAsSibling(insertLocation, paragraphText)

Inserts the paragraph text at the specifiec insert location.

[ API set: OneNoteApi 1.1 ]

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

Parameters

insertLocation
OneNote.InsertLocation

The location of the table relative to the current Paragraph.

paragraphText
string

HTML string to append.

Returns

Examples

OneNote.run(function (context) {

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

    // Get the first PageContent on the page
    // Assuming its an outline, get the outline's paragraphs.
    var pageContent = pageContents.getItemAt(0);
    var paragraphs = pageContent.outline.paragraphs;
    var 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.
    return context.sync()
        .then(function () {

            // 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
            return context.sync();
        });
})    
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
}); 

insertTableAsSibling(insertLocation, rowCount, columnCount, values)

Adds a table with the specified number of rows and columns before or after the current paragraph.

[ API set: OneNoteApi 1.1 ]

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

Parameters

insertLocation
OneNote.InsertLocation

The location of the table relative to the current Paragraph.

rowCount
number

The number of rows in the table.

columnCount
number

The number of columns in the table.

values
string[][]

Optional 2D array. Cells are filled if the corresponding strings are specified in the array.

Returns

OneNote.Table

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

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

Parameters

option
string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns

Remarks

In addition to this signature, this method has the following signatures:

load(option?: { select?: string; expand?: string; }): OneNote.Paragraph - Where option.select is a comma-delimited string that specifies the properties to load, and options.expand is a comma-delimited string that specifies the navigation properties to load.

load(option?: { select?: string; expand?: string; top?: number; skip?: number }): OneNote.Paragraph - Only available on collection types. It is similar to the preceding signature. Option.top specifies the maximum number of collection items that can be included in the result. Option.skip specifies the number of items that are to be skipped and not included in the result. If option.top is specified, the result set will start after skipping the specified number of items.

Examples

OneNote.run(function (context) {

    // Get the collection of pageContent items from the page.
    var 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.
    var pageContent = pageContents._GetItem(0);
    var 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.
    return context.sync()
        .then(function () {

            // Write the text.                  
            $.each(paragraphs.items, function(index, paragraph) {
                console.log("Paragraph type: " + paragraph.type);
                console.log("Paragraph ID: " + paragraph.id);
            });
        });
})        
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
}); 
OneNote.run(function(context) {
    var app = context.application;

    // Gets the active outline
    var outline = app.getActiveOutline();

    // load nested paragraphs and their types.
    outline.load("paragraphs/type");

    return context.sync().then(function () {
        var paragraphs = outline.paragraphs.items;

        var promise;
        // for each nested paragraphs, load tables only
        for (var i = 0; i < paragraphs.length; i++) {
            var paragraph = paragraphs[i];
            if (paragraph.type == "Table") {
                paragraph.load("table/id");
                promise =  context.sync().then(function() {
                    console.log(paragraph.table.id);
                });
            }
        }
        return promise;
    })
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

toJSON()

toJSON(): OneNote.Interfaces.ParagraphData;

Returns

track()

Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for context.trackedObjects.add(thisObject). If you are using this object across ".sync" calls and outside the sequential execution of a ".run" batch, and get an "InvalidObjectPath" error when setting a property or invoking a method on the object, you needed to have added the object to the tracked object collection when the object was first created.

track(): OneNote.Paragraph;

Returns

untrack()

Release the memory associated with this object, if it has previously been tracked. This call is shorthand for context.trackedObjects.remove(thisObject). Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You will need to call "context.sync()" before the memory release takes effect.

untrack(): OneNote.Paragraph;

Returns