Word.List class

Contains a collection of Word.Paragraph objects.

Extends

Remarks

[ API set: WordApi 1.3 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/20-lists/insert-list.yaml

// This example starts a new list with the second paragraph.
await Word.run(async (context) => {
  const paragraphs: Word.ParagraphCollection = context.document.body.paragraphs;
  paragraphs.load("$none");

  await context.sync();

  // Start new list using the second paragraph.
  const list: Word.List = paragraphs.items[1].startNewList();
  list.load("$none");

  await context.sync();

  // To add new items to the list, use Start or End on the insertLocation parameter.
  list.insertParagraph("New list item at the start of the list", "Start");
  const paragraph: Word.Paragraph = list.insertParagraph("New list item at the end of the list (set to list level 5)", "End");

  // Set up list level for the list item.
  paragraph.listItem.level = 4;

  // To add paragraphs outside the list, use Before or After.
  list.insertParagraph("New paragraph goes after (not part of the list)", "After");

  await context.sync();
});

Properties

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

id

Gets the list's id.

levelExistences

Checks whether each of the 9 levels exists in the list. A true value indicates the level exists, which means there is at least one list item at that level.

levelTypes

Gets all 9 level types in the list. Each type can be 'Bullet', 'Number', or 'Picture'.

paragraphs

Gets paragraphs in the list.

Methods

getLevelParagraphs(level)

Gets the paragraphs that occur at the specified level in the list.

getLevelString(level)

Gets the bullet, number, or picture at the specified level as a string.

insertParagraph(paragraphText, insertLocation)

Inserts a paragraph at the specified location.

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

setLevelAlignment(level, alignment)

Sets the alignment of the bullet, number, or picture at the specified level in the list.

setLevelAlignment(level, alignmentString)

Sets the alignment of the bullet, number, or picture at the specified level in the list.

setLevelBullet(level, listBullet, charCode, fontName)

Sets the bullet format at the specified level in the list. If the bullet is 'Custom', the charCode is required.

setLevelBullet(level, listBulletString, charCode, fontName)

Sets the bullet format at the specified level in the list. If the bullet is 'Custom', the charCode is required.

setLevelIndents(level, textIndent, bulletNumberPictureIndent)

Sets the two indents of the specified level in the list.

setLevelNumbering(level, listNumbering, formatString)

Sets the numbering format at the specified level in the list.

setLevelNumbering(level, listNumberingString, formatString)

Sets the numbering format at the specified level in the list.

setLevelStartingNumber(level, startingNumber)

Sets the starting number at the specified level in the list. Default value is 1.

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that's passed to it.) Whereas the original Word.List object is an API object, the toJSON method returns a plain JavaScript object (typed as Word.Interfaces.ListData) that contains shallow copies of any loaded child properties from the original object.

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're 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 need to add the object to the tracked object collection when the object was first created. If this object is part of a collection, you should also track the parent collection.

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'll need to call context.sync() before the memory release takes effect.

Property Details

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

context: RequestContext;

Property Value

id

Gets the list's id.

readonly id: number;

Property Value

number

Remarks

[ API set: WordApi 1.3 ]

levelExistences

Checks whether each of the 9 levels exists in the list. A true value indicates the level exists, which means there is at least one list item at that level.

readonly levelExistences: boolean[];

Property Value

boolean[]

Remarks

[ API set: WordApi 1.3 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/20-lists/organize-list.yaml

// Gets information about the first list in the document.
await Word.run(async (context) => {
  const lists: Word.ListCollection = context.document.body.lists;
  lists.load("items");

  await context.sync();

  if (lists.items.length === 0) {
    console.warn("There are no lists in this document.");
    return;
  }
  
  // Get the first list.
  const list: Word.List = lists.getFirst();
  list.load("levelTypes,levelExistences");

  await context.sync();

  const levelTypes  = list.levelTypes;
  console.log("Level types of the first list:");
  for (let i = 0; i < levelTypes.length; i++) {
    console.log(`- Level ${i + 1} (index ${i}): ${levelTypes[i]}`);
  }

  const levelExistences = list.levelExistences;
  console.log("Level existences of the first list:");
  for (let i = 0; i < levelExistences.length; i++) {
    console.log(`- Level ${i + 1} (index ${i}): ${levelExistences[i]}`);
  }
});

levelTypes

Gets all 9 level types in the list. Each type can be 'Bullet', 'Number', or 'Picture'.

readonly levelTypes: Word.ListLevelType[];

Property Value

Remarks

[ API set: WordApi 1.3 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/20-lists/organize-list.yaml

// Gets information about the first list in the document.
await Word.run(async (context) => {
  const lists: Word.ListCollection = context.document.body.lists;
  lists.load("items");

  await context.sync();

  if (lists.items.length === 0) {
    console.warn("There are no lists in this document.");
    return;
  }
  
  // Get the first list.
  const list: Word.List = lists.getFirst();
  list.load("levelTypes,levelExistences");

  await context.sync();

  const levelTypes  = list.levelTypes;
  console.log("Level types of the first list:");
  for (let i = 0; i < levelTypes.length; i++) {
    console.log(`- Level ${i + 1} (index ${i}): ${levelTypes[i]}`);
  }

  const levelExistences = list.levelExistences;
  console.log("Level existences of the first list:");
  for (let i = 0; i < levelExistences.length; i++) {
    console.log(`- Level ${i + 1} (index ${i}): ${levelExistences[i]}`);
  }
});

paragraphs

Gets paragraphs in the list.

readonly paragraphs: Word.ParagraphCollection;

Property Value

Remarks

[ API set: WordApi 1.3 ]

Method Details

getLevelParagraphs(level)

Gets the paragraphs that occur at the specified level in the list.

getLevelParagraphs(level: number): Word.ParagraphCollection;

Parameters

level

number

Required. The level in the list.

Returns

Remarks

[ API set: WordApi 1.3 ]

getLevelString(level)

Gets the bullet, number, or picture at the specified level as a string.

getLevelString(level: number): OfficeExtension.ClientResult<string>;

Parameters

level

number

Required. The level in the list.

Returns

Remarks

[ API set: WordApi 1.3 ]

insertParagraph(paragraphText, insertLocation)

Inserts a paragraph at the specified location.

insertParagraph(paragraphText: string, insertLocation: Word.InsertLocation.start | Word.InsertLocation.end | Word.InsertLocation.before | Word.InsertLocation.after | "Start" | "End" | "Before" | "After"): Word.Paragraph;

Parameters

paragraphText

string

Required. The paragraph text to be inserted.

insertLocation

start | end | before | after | "Start" | "End" | "Before" | "After"

Required. The value must be 'Start', 'End', 'Before', or 'After'.

Returns

Remarks

[ API set: WordApi 1.3 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/20-lists/insert-list.yaml

// This example starts a new list with the second paragraph.
await Word.run(async (context) => {
  const paragraphs: Word.ParagraphCollection = context.document.body.paragraphs;
  paragraphs.load("$none");

  await context.sync();

  // Start new list using the second paragraph.
  const list: Word.List = paragraphs.items[1].startNewList();
  list.load("$none");

  await context.sync();

  // To add new items to the list, use Start or End on the insertLocation parameter.
  list.insertParagraph("New list item at the start of the list", "Start");
  const paragraph: Word.Paragraph = list.insertParagraph("New list item at the end of the list (set to list level 5)", "End");

  // Set up list level for the list item.
  paragraph.listItem.level = 4;

  // To add paragraphs outside the list, use Before or After.
  list.insertParagraph("New paragraph goes after (not part of the list)", "After");

  await context.sync();
});

load(options)

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

load(options?: Word.Interfaces.ListLoadOptions): Word.List;

Parameters

options
Word.Interfaces.ListLoadOptions

Provides options for which properties of the object to load.

Returns

load(propertyNames)

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

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

Parameters

propertyNames

string | string[]

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

Returns

load(propertyNamesAndPaths)

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

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

Parameters

propertyNamesAndPaths

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

propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.

Returns

setLevelAlignment(level, alignment)

Sets the alignment of the bullet, number, or picture at the specified level in the list.

setLevelAlignment(level: number, alignment: Word.Alignment): void;

Parameters

level

number

Required. The level in the list.

alignment
Word.Alignment

Required. The level alignment that must be 'Left', 'Centered', or 'Right'.

Returns

void

Remarks

[ API set: WordApi 1.3 ]

setLevelAlignment(level, alignmentString)

Sets the alignment of the bullet, number, or picture at the specified level in the list.

setLevelAlignment(level: number, alignmentString: "Mixed" | "Unknown" | "Left" | "Centered" | "Right" | "Justified"): void;

Parameters

level

number

Required. The level in the list.

alignmentString

"Mixed" | "Unknown" | "Left" | "Centered" | "Right" | "Justified"

Required. The level alignment that must be 'Left', 'Centered', or 'Right'.

Returns

void

Remarks

[ API set: WordApi 1.3 ]

setLevelBullet(level, listBullet, charCode, fontName)

Sets the bullet format at the specified level in the list. If the bullet is 'Custom', the charCode is required.

setLevelBullet(level: number, listBullet: Word.ListBullet, charCode?: number, fontName?: string): void;

Parameters

level

number

Required. The level in the list.

listBullet
Word.ListBullet

Required. The bullet.

charCode

number

Optional. The bullet character's code value. Used only if the bullet is 'Custom'.

fontName

string

Optional. The bullet's font name. Used only if the bullet is 'Custom'.

Returns

void

Remarks

[ API set: WordApi 1.3 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/20-lists/organize-list.yaml

// Inserts a list starting with the first paragraph then set numbering and bullet types of the list items.
await Word.run(async (context) => {
  const paragraphs: Word.ParagraphCollection = context.document.body.paragraphs;
  paragraphs.load("$none");

  await context.sync();

  // Use the first paragraph to start a new list.
  const list: Word.List = paragraphs.items[0].startNewList();
  list.load("$none");

  await context.sync();

  // To add new items to the list, use Start or End on the insertLocation parameter.
  list.insertParagraph("New list item at the start of the list", "Start");
  const paragraph: Word.Paragraph = list.insertParagraph("New list item at the end of the list (set to list level 5)", "End");

  // Set numbering for list level 1.
  list.setLevelNumbering(0, Word.ListNumbering.arabic);

  // Set bullet type for list level 5.
  list.setLevelBullet(4, Word.ListBullet.arrow);

  // Set list level for the last item in this list.
  paragraph.listItem.level = 4;

  list.load("levelTypes");

  await context.sync();
});

setLevelBullet(level, listBulletString, charCode, fontName)

Sets the bullet format at the specified level in the list. If the bullet is 'Custom', the charCode is required.

setLevelBullet(level: number, listBulletString: "Custom" | "Solid" | "Hollow" | "Square" | "Diamonds" | "Arrow" | "Checkmark", charCode?: number, fontName?: string): void;

Parameters

level

number

Required. The level in the list.

listBulletString

"Custom" | "Solid" | "Hollow" | "Square" | "Diamonds" | "Arrow" | "Checkmark"

Required. The bullet.

charCode

number

Optional. The bullet character's code value. Used only if the bullet is 'Custom'.

fontName

string

Optional. The bullet's font name. Used only if the bullet is 'Custom'.

Returns

void

Remarks

[ API set: WordApi 1.3 ]

setLevelIndents(level, textIndent, bulletNumberPictureIndent)

Sets the two indents of the specified level in the list.

setLevelIndents(level: number, textIndent: number, bulletNumberPictureIndent: number): void;

Parameters

level

number

Required. The level in the list.

textIndent

number

Required. The text indent in points. It is the same as paragraph left indent.

bulletNumberPictureIndent

number

Required. The relative indent, in points, of the bullet, number, or picture. It is the same as paragraph first line indent.

Returns

void

Remarks

[ API set: WordApi 1.3 ]

setLevelNumbering(level, listNumbering, formatString)

Sets the numbering format at the specified level in the list.

setLevelNumbering(level: number, listNumbering: Word.ListNumbering, formatString?: Array<string | number>): void;

Parameters

level

number

Required. The level in the list.

listNumbering
Word.ListNumbering

Required. The ordinal format.

formatString

Array<string | number>

Optional. The numbering string format defined as an array of strings and/or integers. Each integer is a level of number type that is higher than or equal to this level. For example, an array of ["(", level - 1, ".", level, ")"] can define the format of "(2.c)", where 2 is the parent's item number and c is this level's item number.

Returns

void

Remarks

[ API set: WordApi 1.3 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/20-lists/organize-list.yaml

// Inserts a list starting with the first paragraph then set numbering and bullet types of the list items.
await Word.run(async (context) => {
  const paragraphs: Word.ParagraphCollection = context.document.body.paragraphs;
  paragraphs.load("$none");

  await context.sync();

  // Use the first paragraph to start a new list.
  const list: Word.List = paragraphs.items[0].startNewList();
  list.load("$none");

  await context.sync();

  // To add new items to the list, use Start or End on the insertLocation parameter.
  list.insertParagraph("New list item at the start of the list", "Start");
  const paragraph: Word.Paragraph = list.insertParagraph("New list item at the end of the list (set to list level 5)", "End");

  // Set numbering for list level 1.
  list.setLevelNumbering(0, Word.ListNumbering.arabic);

  // Set bullet type for list level 5.
  list.setLevelBullet(4, Word.ListBullet.arrow);

  // Set list level for the last item in this list.
  paragraph.listItem.level = 4;

  list.load("levelTypes");

  await context.sync();
});

setLevelNumbering(level, listNumberingString, formatString)

Sets the numbering format at the specified level in the list.

setLevelNumbering(level: number, listNumberingString: "None" | "Arabic" | "UpperRoman" | "LowerRoman" | "UpperLetter" | "LowerLetter", formatString?: Array<string | number>): void;

Parameters

level

number

Required. The level in the list.

listNumberingString

"None" | "Arabic" | "UpperRoman" | "LowerRoman" | "UpperLetter" | "LowerLetter"

Required. The ordinal format.

formatString

Array<string | number>

Optional. The numbering string format defined as an array of strings and/or integers. Each integer is a level of number type that is higher than or equal to this level. For example, an array of ["(", level - 1, ".", level, ")"] can define the format of "(2.c)", where 2 is the parent's item number and c is this level's item number.

Returns

void

Remarks

[ API set: WordApi 1.3 ]

setLevelStartingNumber(level, startingNumber)

Sets the starting number at the specified level in the list. Default value is 1.

setLevelStartingNumber(level: number, startingNumber: number): void;

Parameters

level

number

Required. The level in the list.

startingNumber

number

Required. The number to start with.

Returns

void

Remarks

[ API set: WordApi 1.3 ]

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that's passed to it.) Whereas the original Word.List object is an API object, the toJSON method returns a plain JavaScript object (typed as Word.Interfaces.ListData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Word.Interfaces.ListData;

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're 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 need to add the object to the tracked object collection when the object was first created. If this object is part of a collection, you should also track the parent collection.

track(): Word.List;

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'll need to call context.sync() before the memory release takes effect.

untrack(): Word.List;

Returns