Word.Paragraph class

表示选定内容、区域、内容控件或文档正文中的单个段落。

扩展

注解

API 集:WordApi 1.1

使用方

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/get-paragraph-on-insertion-point.yaml

await Word.run(async (context) => {
  // The collection of paragraphs of the current selection returns the full paragraphs contained in it.
  const paragraph: Word.Paragraph = context.document.getSelection().paragraphs.getFirst();
  paragraph.load("text");

  await context.sync();
  console.log(paragraph.text);
});

属性

alignment

指定段落的对齐方式。 值可以是 leftcenteredright 或 。justified

borders

返回 BorderUniversalCollection 表示段落所有边框的对象。

contentControls

获取段落中的对象集合 ContentControl

context

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

endnotes

获取段落中尾注的集合。

fields

获取段落中字段的集合。

firstLineIndent

指定首行或悬挂缩进的值(以磅为单位)。 用正数设置首行缩进的尺寸,用负数设置悬挂缩进的尺寸。

font

获取段落的文本格式。 使用此对象获取和设置字体名称、大小、颜色和其他属性。

footnotes

获取段落中脚注的集合。

inlinePictures

获取段落中的对象集合 InlinePicture 。 该集合不包括浮动图像。

isLastParagraph

指明 paragraph 是其父正文内的最后一个段落。

isListItem

检查 paragraph 是否为 listItem。

leftIndent

指定段落的左缩进值(以磅为单位)。

lineSpacing

指定指定段落的行距(以磅为单位)。 在 Word UI 中,该值应除以 12。

lineUnitAfter

指定段落后网格线的间距。

lineUnitBefore

以网格线为单位指定段落前面的间距。

list

获取 paragraph 所属的 List。 如果段落不在列表中,则引发 ItemNotFound 错误。

listItem

获取 paragraph 的 ListItem。 如果段落不在列表中,则引发 ItemNotFound 错误。

listItemOrNullObject

获取 paragraph 的 ListItem。 如果段落不是列表的一部分,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

listOrNullObject

获取 paragraph 所属的 List。 如果段落不在列表中,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

outlineLevel

指定段落的大纲级别。

parentBody

获取 paragraph 的父正文。

parentContentControl

获取包含段落的内容控件。 如果没有父内容控件,则引发 ItemNotFound 错误。

parentContentControlOrNullObject

获取包含段落的内容控件。 如果没有父内容控件,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

parentTable

获取包含 paragraph 的 table。 如果表中未包含,则引发 ItemNotFound 错误。

parentTableCell

获取包含 paragraph 的 tableCell。 如果表单元格中未包含错误,则引发 ItemNotFound 错误。

parentTableCellOrNullObject

获取包含 paragraph 的 tableCell。 如果它未包含在表单元格中,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

parentTableOrNullObject

获取包含 paragraph 的 table。 如果它未包含在表中,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

rightIndent

指定段落的右缩进值(以磅为单位)。

shading

返回 ShadingUniversal 引用段落底纹格式的对象。

shapes

获取定位在段落中的对象集合 Shape ,包括内联和浮动形状。 目前仅支持以下形状:文本框、几何形状、组、图片和画布。

spaceAfter

指定段落后段距(以磅为单位)。

spaceBefore

指定段落前的间距(以磅为单位)。

style

指定段落的样式名称。 请对自定义样式和本地化样式名称使用此属性。 若要使用可以在区域设置之间移植的嵌入样式,请参阅“styleBuiltIn”属性。

styleBuiltIn

指定段落的内置样式名称。 请对可以在区域设置之间移植的嵌入样式使用此属性。 若要使用自定义样式或本地化样式名称,请参阅“style”属性。

tableNestingLevel

获取 paragraph 的表级别。 如果段落不在表格中,它将返回 0。

text

获取段落的文本。

uniqueLocalId

获取表示当前会话中段落标识符的字符串。 ID 采用不带大括号的标准 8-4-4-4-12 GUID 格式,并且在会话和共同创作者之间有所不同。

方法

attachToList(listId, level)

将 paragraph 加入指定级别的现有 list。 如果 paragraph 无法加入 list 或已是 listItem,则无法执行此方法。

clear()

清除对象的内容 Paragraph 。 用户可以对已清除的内容执行撤消操作。

closeUp()

删除段落前的任何空格。

delete()

从文档中删除段落及其内容。

detachFromList()

如果此段落是列表项目的话,从列表中移出此段落。

getAnnotations()

获取对此 Paragraph 对象设置的批注。

getComments()

获取与段落关联的注释。

getContentControls(options)

获取段落中当前支持的内容控件。

getHtml()

获取对象的 HTML 表示形式 Paragraph 。 在网页或 HTML 查看器中呈现时,格式将与文档的格式非常匹配,但不完全匹配。 此方法不会为不同平台上的同一文档返回完全相同的 HTML, (Windows、Mac、Word Web 等 ) 。 如果需要精确的保真度或跨平台的一致性,请使用 Paragraph.getOoxml() 返回的 XML 并将其转换为 HTML。

getNext()

获取下一个段落。 如果段落是最后一个段落,则引发 ItemNotFound 错误。

getNextOrNullObject()

获取下一个段落。 如果段落是最后一个段落,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

getOoxml()

获取对象的 Paragraph Office Open XML (OOXML) 表示形式。

getPrevious()

获取上一个段落。 如果段落是第一个段落,则引发 ItemNotFound 错误。

getPreviousOrNullObject()

获取上一个段落。 如果段落是第一个段落,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

getRange(rangeLocation)

获取整个段落或段落的起点/终点,作为一个范围。

getReviewedText(changeTrackingVersion)

根据所选内容获取审阅的文本 ChangeTrackingVersion

getReviewedText(changeTrackingVersion)

根据所选内容获取审阅的文本 ChangeTrackingVersion

getText(options)

返回段落的文本。 这不包括方程式、图形 (,例如图像、视频、绘图) 和标记各种内容 (的特殊字符,例如,对于内容控件、字段、注释、脚注、尾注) 。 默认情况下,隐藏的文字和标记为已删除的文字将被排除在外。

getTextRanges(endingMarks, trimSpacing)

使用标点符号和其他结束标记获取段落中的文本范围。

getTrackedChanges()

获取段落中对象的 TrackedChange 集合。

indent()

将段落缩进一级。

indentCharacterWidth(count)

将段落缩进指定的字符数。

indentFirstLineCharacterWidth(count)

将段落首行缩进指定的字符数。

insertAnnotations(annotations)

在此对象上 Paragraph 插入批注。

insertBreak(breakType, insertLocation)

在主文档的指定位置插入分隔符。

insertCanvas(insertShapeOptions)

在文本前面插入浮动画布,其定位点位于段落的开头。

insertContentControl(contentControlType)

Paragraph使用内容控件包装对象。

insertFileFromBase64(base64File, insertLocation)

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

insertGeometricShape(geometricShapeType, insertShapeOptions)

在文本前面插入几何形状,其定位点位于段落的开头。

insertGeometricShape(geometricShapeType, insertShapeOptions)

在文本前面插入几何形状,其定位点位于段落的开头。

insertHtml(html, insertLocation)

将 HTML 插入到段落中的指定位置。

insertInlinePictureFromBase64(base64EncodedImage, insertLocation)

将图片插入到段落中的指定位置。

insertOoxml(ooxml, insertLocation)

在指定位置将 OOXML 插入段落中。

insertParagraph(paragraphText, insertLocation)

在指定位置插入段落。

insertPictureFromBase64(base64EncodedImage, insertShapeOptions)

在文本前面插入浮动图片,其定位点位于段落的开头。

insertTable(rowCount, columnCount, insertLocation, values)

插入包含指定行数和列数的 table。

insertText(text, insertLocation)

将文本插入到段落中的指定位置。

insertTextBox(text, insertShapeOptions)

在文本前面插入一个浮动文本框,其定位点位于段落的开头。

joinList()

将列表段落与此段落上方或下方最接近的列表联接。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

next(count)

返回 Paragraph 表示下一段的对象。

openOrCloseUp()

切换段落前的间距。

openUp()

将段落前的间距设置为 12 磅。

outdent()

删除段落的一级缩进。

outlineDemote()

将标题级别样式 (标题 1 到标题 8) 应用到段落。

outlineDemoteToBody()

通过应用“普通”样式将段落降级为正文文本。

outlinePromote()

将之前的标题级别样式 (标题 1 到标题 8) 应用到段落。

previous(count)

将上一段作为 Paragraph 对象返回。

reset()

删除手动段落格式(不使用样式应用的格式)。

resetAdvanceTo()

将使用自定义列表级别的段落重置为原始级别设置。

search(searchText, searchOptions)

使用指定的搜索选项对对象范围执行 Paragraph 搜索。 搜索结果是对象的 Range 集合。

select(selectionMode)

选择并在 Word UI 中导航到段落。

select(selectionMode)

选择并在 Word UI 中导航到段落。

selectNumber()

选择列表中的编号或项目符号。

separateList()

将列表分隔为两个单独的列表。 对于编号的列表,新列表将从起始编号(通常为 1)开始重新编号。

set(properties, options)

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

set(properties)

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

space1()

将段落设置为单倍行距。

space1Pt5()

将段落设置为 1.5 倍行距。

space2()

将段落设置为双倍行距。

split(delimiters, trimDelimiters, trimSpacing)

使用分隔符将段落拆分为多个子范围。

startNewList()

生成包含此 paragraph 的新 list。 如果此 paragraph 已是 listItem,则无法执行此方法。

tabHangingIndent(count)

将悬挂缩进量设置为指定的制表位数。

tabIndent(count)

将段落的左缩进设置为指定的制表位数。

toJSON()

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

track()

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

untrack()

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

活动

onCommentAdded

在添加新批注时发生。

onCommentChanged

更改注释或其回复时发生。

onCommentDeleted

删除注释时发生。

onCommentDeselected

取消选择批注时出现。

onCommentSelected

选中批注时出现。

属性详细信息

alignment

指定段落的对齐方式。 值可以是 leftcenteredright 或 。justified

alignment: Word.Alignment | "Mixed" | "Unknown" | "Left" | "Centered" | "Right" | "Justified";

属性值

Word.Alignment | "Mixed" | "Unknown" | "Left" | "Centered" | "Right" | "Justified"

注解

API 集:WordApi 1.1

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/paragraph-properties.yaml

await Word.run(async (context) => {
  // Center last paragraph alignment.
  context.document.body.paragraphs.getLast().alignment = "Centered";

  await context.sync();
});

borders

返回 BorderUniversalCollection 表示段落所有边框的对象。

readonly borders: Word.BorderUniversalCollection;

属性值

注解

API 集:WordApiDesktop 1.3

contentControls

获取段落中的对象集合 ContentControl

readonly contentControls: Word.ContentControlCollection;

属性值

注解

API 集:WordApi 1.1

context

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

context: RequestContext;

属性值

endnotes

获取段落中尾注的集合。

readonly endnotes: Word.NoteItemCollection;

属性值

注解

API 集:WordApi 1.5

fields

获取段落中字段的集合。

readonly fields: Word.FieldCollection;

属性值

注解

API 集:WordApi 1.4

firstLineIndent

指定首行或悬挂缩进的值(以磅为单位)。 用正数设置首行缩进的尺寸,用负数设置悬挂缩进的尺寸。

firstLineIndent: number;

属性值

number

注解

API 集:WordApi 1.1

font

获取段落的文本格式。 使用此对象获取和设置字体名称、大小、颜色和其他属性。

readonly font: Word.Font;

属性值

注解

API 集:WordApi 1.1

footnotes

获取段落中脚注的集合。

readonly footnotes: Word.NoteItemCollection;

属性值

注解

API 集:WordApi 1.5

inlinePictures

获取段落中的对象集合 InlinePicture 。 该集合不包括浮动图像。

readonly inlinePictures: Word.InlinePictureCollection;

属性值

注解

API 集:WordApi 1.1

isLastParagraph

指明 paragraph 是其父正文内的最后一个段落。

readonly isLastParagraph: boolean;

属性值

boolean

注解

API 集:WordApi 1.3

isListItem

检查 paragraph 是否为 listItem。

readonly isListItem: boolean;

属性值

boolean

注解

API 集:WordApi 1.3

leftIndent

指定段落的左缩进值(以磅为单位)。

leftIndent: number;

属性值

number

注解

API 集:WordApi 1.1

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/paragraph-properties.yaml

await Word.run(async (context) => {
  // Indent the first paragraph.
  context.document.body.paragraphs.getFirst().leftIndent = 75; //units = points

  return context.sync();
});

lineSpacing

指定指定段落的行距(以磅为单位)。 在 Word UI 中,该值应除以 12。

lineSpacing: number;

属性值

number

注解

API 集:WordApi 1.1

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/paragraph-properties.yaml

await Word.run(async (context) => {
  // Adjust line spacing.
  context.document.body.paragraphs.getFirst().lineSpacing = 20;

  await context.sync();
});

lineUnitAfter

指定段落后网格线的间距。

lineUnitAfter: number;

属性值

number

注解

API 集:WordApi 1.1

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/paragraph-properties.yaml

await Word.run(async (context) => {
  // Set the space (in line units) after the first paragraph.
  context.document.body.paragraphs.getFirst().lineUnitAfter = 1;

  await context.sync();
});

lineUnitBefore

以网格线为单位指定段落前面的间距。

lineUnitBefore: number;

属性值

number

注解

API 集:WordApi 1.1

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/paragraph-properties.yaml

await Word.run(async (context) => {
  // Set the space (in line units) before the first paragraph.
  context.document.body.paragraphs.getFirst().lineUnitBefore = 1;

  await context.sync();
});

list

获取 paragraph 所属的 List。 如果段落不在列表中,则引发 ItemNotFound 错误。

readonly list: Word.List;

属性值

注解

API 集:WordApi 1.3

listItem

获取 paragraph 的 ListItem。 如果段落不在列表中,则引发 ItemNotFound 错误。

readonly listItem: Word.ListItem;

属性值

注解

API 集:WordApi 1.3

listItemOrNullObject

获取 paragraph 的 ListItem。 如果段落不是列表的一部分,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

readonly listItemOrNullObject: Word.ListItem;

属性值

注解

API 集:WordApi 1.3

listOrNullObject

获取 paragraph 所属的 List。 如果段落不在列表中,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

readonly listOrNullObject: Word.List;

属性值

注解

API 集:WordApi 1.3

outlineLevel

指定段落的大纲级别。

outlineLevel: number;

属性值

number

注解

API 集:WordApi 1.1

parentBody

获取 paragraph 的父正文。

readonly parentBody: Word.Body;

属性值

注解

API 集:WordApi 1.3

parentContentControl

获取包含段落的内容控件。 如果没有父内容控件,则引发 ItemNotFound 错误。

readonly parentContentControl: Word.ContentControl;

属性值

注解

API 集:WordApi 1.1

parentContentControlOrNullObject

获取包含段落的内容控件。 如果没有父内容控件,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

readonly parentContentControlOrNullObject: Word.ContentControl;

属性值

注解

API 集:WordApi 1.3

parentTable

获取包含 paragraph 的 table。 如果表中未包含,则引发 ItemNotFound 错误。

readonly parentTable: Word.Table;

属性值

注解

API 集:WordApi 1.3

parentTableCell

获取包含 paragraph 的 tableCell。 如果表单元格中未包含错误,则引发 ItemNotFound 错误。

readonly parentTableCell: Word.TableCell;

属性值

注解

API 集:WordApi 1.3

parentTableCellOrNullObject

获取包含 paragraph 的 tableCell。 如果它未包含在表单元格中,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

readonly parentTableCellOrNullObject: Word.TableCell;

属性值

注解

API 集:WordApi 1.3

parentTableOrNullObject

获取包含 paragraph 的 table。 如果它未包含在表中,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

readonly parentTableOrNullObject: Word.Table;

属性值

注解

API 集:WordApi 1.3

rightIndent

指定段落的右缩进值(以磅为单位)。

rightIndent: number;

属性值

number

注解

API 集:WordApi 1.1

shading

返回 ShadingUniversal 引用段落底纹格式的对象。

readonly shading: Word.ShadingUniversal;

属性值

注解

API 集:WordApiDesktop 1.3

shapes

获取定位在段落中的对象集合 Shape ,包括内联和浮动形状。 目前仅支持以下形状:文本框、几何形状、组、图片和画布。

readonly shapes: Word.ShapeCollection;

属性值

注解

API 集:WordApiDesktop 1.2

重要提示: 请注意,随着时间的推移,可能会支持其他类型的形状。 因此,加载项应请求和处理特定类型的形状。

spaceAfter

指定段落后段距(以磅为单位)。

spaceAfter: number;

属性值

number

注解

API 集:WordApi 1.1

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/paragraph-properties.yaml

await Word.run(async (context) => {
  // Set the space (in points) after the first paragraph.
  context.document.body.paragraphs.getFirst().spaceAfter = 20;

  await context.sync();
});

spaceBefore

指定段落前的间距(以磅为单位)。

spaceBefore: number;

属性值

number

注解

API 集:WordApi 1.1

style

指定段落的样式名称。 请对自定义样式和本地化样式名称使用此属性。 若要使用可以在区域设置之间移植的嵌入样式,请参阅“styleBuiltIn”属性。

style: string;

属性值

string

注解

API 集:WordApi 1.1

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-styles.yaml

// Applies the specified style to a paragraph.
await Word.run(async (context) => {
  const styleName = (document.getElementById("style-name-to-use") as HTMLInputElement).value;
  if (styleName == "") {
    console.warn("Enter a style name to apply.");
    return;
  }

  const style: Word.Style = context.document.getStyles().getByNameOrNullObject(styleName);
  style.load();
  await context.sync();

  if (style.isNullObject) {
    console.warn(`There's no existing style with the name '${styleName}'.`);
  } else if (style.type != Word.StyleType.paragraph) {
    console.log(`The '${styleName}' style isn't a paragraph style.`);
  } else {
    const body: Word.Body = context.document.body;
    body.clear();
    body.insertParagraph(
      "Do you want to create a solution that extends the functionality of Word? You can use the Office Add-ins platform to extend Word clients running on the web, on a Windows desktop, or on a Mac.",
      "Start"
    );
    const paragraph: Word.Paragraph = body.paragraphs.getFirst();
    paragraph.style = style.nameLocal;
    console.log(`'${styleName}' style applied to first paragraph.`);
  }
});

styleBuiltIn

指定段落的内置样式名称。 请对可以在区域设置之间移植的嵌入样式使用此属性。 若要使用自定义样式或本地化样式名称,请参阅“style”属性。

styleBuiltIn: Word.BuiltInStyleName | "Other" | "Normal" | "Heading1" | "Heading2" | "Heading3" | "Heading4" | "Heading5" | "Heading6" | "Heading7" | "Heading8" | "Heading9" | "Toc1" | "Toc2" | "Toc3" | "Toc4" | "Toc5" | "Toc6" | "Toc7" | "Toc8" | "Toc9" | "FootnoteText" | "Header" | "Footer" | "Caption" | "FootnoteReference" | "EndnoteReference" | "EndnoteText" | "Title" | "Subtitle" | "Hyperlink" | "Strong" | "Emphasis" | "NoSpacing" | "ListParagraph" | "Quote" | "IntenseQuote" | "SubtleEmphasis" | "IntenseEmphasis" | "SubtleReference" | "IntenseReference" | "BookTitle" | "Bibliography" | "TocHeading" | "TableGrid" | "PlainTable1" | "PlainTable2" | "PlainTable3" | "PlainTable4" | "PlainTable5" | "TableGridLight" | "GridTable1Light" | "GridTable1Light_Accent1" | "GridTable1Light_Accent2" | "GridTable1Light_Accent3" | "GridTable1Light_Accent4" | "GridTable1Light_Accent5" | "GridTable1Light_Accent6" | "GridTable2" | "GridTable2_Accent1" | "GridTable2_Accent2" | "GridTable2_Accent3" | "GridTable2_Accent4" | "GridTable2_Accent5" | "GridTable2_Accent6" | "GridTable3" | "GridTable3_Accent1" | "GridTable3_Accent2" | "GridTable3_Accent3" | "GridTable3_Accent4" | "GridTable3_Accent5" | "GridTable3_Accent6" | "GridTable4" | "GridTable4_Accent1" | "GridTable4_Accent2" | "GridTable4_Accent3" | "GridTable4_Accent4" | "GridTable4_Accent5" | "GridTable4_Accent6" | "GridTable5Dark" | "GridTable5Dark_Accent1" | "GridTable5Dark_Accent2" | "GridTable5Dark_Accent3" | "GridTable5Dark_Accent4" | "GridTable5Dark_Accent5" | "GridTable5Dark_Accent6" | "GridTable6Colorful" | "GridTable6Colorful_Accent1" | "GridTable6Colorful_Accent2" | "GridTable6Colorful_Accent3" | "GridTable6Colorful_Accent4" | "GridTable6Colorful_Accent5" | "GridTable6Colorful_Accent6" | "GridTable7Colorful" | "GridTable7Colorful_Accent1" | "GridTable7Colorful_Accent2" | "GridTable7Colorful_Accent3" | "GridTable7Colorful_Accent4" | "GridTable7Colorful_Accent5" | "GridTable7Colorful_Accent6" | "ListTable1Light" | "ListTable1Light_Accent1" | "ListTable1Light_Accent2" | "ListTable1Light_Accent3" | "ListTable1Light_Accent4" | "ListTable1Light_Accent5" | "ListTable1Light_Accent6" | "ListTable2" | "ListTable2_Accent1" | "ListTable2_Accent2" | "ListTable2_Accent3" | "ListTable2_Accent4" | "ListTable2_Accent5" | "ListTable2_Accent6" | "ListTable3" | "ListTable3_Accent1" | "ListTable3_Accent2" | "ListTable3_Accent3" | "ListTable3_Accent4" | "ListTable3_Accent5" | "ListTable3_Accent6" | "ListTable4" | "ListTable4_Accent1" | "ListTable4_Accent2" | "ListTable4_Accent3" | "ListTable4_Accent4" | "ListTable4_Accent5" | "ListTable4_Accent6" | "ListTable5Dark" | "ListTable5Dark_Accent1" | "ListTable5Dark_Accent2" | "ListTable5Dark_Accent3" | "ListTable5Dark_Accent4" | "ListTable5Dark_Accent5" | "ListTable5Dark_Accent6" | "ListTable6Colorful" | "ListTable6Colorful_Accent1" | "ListTable6Colorful_Accent2" | "ListTable6Colorful_Accent3" | "ListTable6Colorful_Accent4" | "ListTable6Colorful_Accent5" | "ListTable6Colorful_Accent6" | "ListTable7Colorful" | "ListTable7Colorful_Accent1" | "ListTable7Colorful_Accent2" | "ListTable7Colorful_Accent3" | "ListTable7Colorful_Accent4" | "ListTable7Colorful_Accent5" | "ListTable7Colorful_Accent6";

属性值

Word.BuiltInStyleName | "Other" | "Normal" | "Heading1" | "Heading2" | "Heading3" | "Heading4" | "Heading5" | "Heading6" | "Heading7" | "Heading8" | "Heading9" | "Toc1" | "Toc2" | "Toc3" | "Toc4" | "Toc5" | "Toc6" | "Toc7" | "Toc8" | "Toc9" | "FootnoteText" | "Header" | "Footer" | "Caption" | "FootnoteReference" | "EndnoteReference" | "EndnoteText" | "Title" | "Subtitle" | "Hyperlink" | "Strong" | "Emphasis" | "NoSpacing" | "ListParagraph" | "Quote" | "IntenseQuote" | "SubtleEmphasis" | "IntenseEmphasis" | "SubtleReference" | "IntenseReference" | "BookTitle" | "Bibliography" | "TocHeading" | "TableGrid" | "PlainTable1" | "PlainTable2" | "PlainTable3" | "PlainTable4" | "PlainTable5" | "TableGridLight" | "GridTable1Light" | "GridTable1Light_Accent1" | "GridTable1Light_Accent2" | "GridTable1Light_Accent3" | "GridTable1Light_Accent4" | "GridTable1Light_Accent5" | "GridTable1Light_Accent6" | "GridTable2" | "GridTable2_Accent1" | "GridTable2_Accent2" | "GridTable2_Accent3" | "GridTable2_Accent4" | "GridTable2_Accent5" | "GridTable2_Accent6" | "GridTable3" | "GridTable3_Accent1" | "GridTable3_Accent2" | "GridTable3_Accent3" | "GridTable3_Accent4" | "GridTable3_Accent5" | "GridTable3_Accent6" | "GridTable4" | "GridTable4_Accent1" | "GridTable4_Accent2" | "GridTable4_Accent3" | "GridTable4_Accent4" | "GridTable4_Accent5" | "GridTable4_Accent6" | "GridTable5Dark" | "GridTable5Dark_Accent1" | "GridTable5Dark_Accent2" | "GridTable5Dark_Accent3" | "GridTable5Dark_Accent4" | "GridTable5Dark_Accent5" | "GridTable5Dark_Accent6" | "GridTable6Colorful" | "GridTable6Colorful_Accent1" | "GridTable6Colorful_Accent2" | "GridTable6Colorful_Accent3" | "GridTable6Colorful_Accent4" | "GridTable6Colorful_Accent5" | "GridTable6Colorful_Accent6" | "GridTable7Colorful" | "GridTable7Colorful_Accent1" | "GridTable7Colorful_Accent2" | "GridTable7Colorful_Accent3" | "GridTable7Colorful_Accent4" | "GridTable7Colorful_Accent5" | "GridTable7Colorful_Accent6" | "ListTable1Light" | "ListTable1Light_Accent1" | "ListTable1Light_Accent2" | "ListTable1Light_Accent3" | "ListTable1Light_Accent4" | "ListTable1Light_Accent5" | "ListTable1Light_Accent6" | "ListTable2" | "ListTable2_Accent1" | "ListTable2_Accent2" | "ListTable2_Accent3" | "ListTable2_Accent4" | "ListTable2_Accent5" | "ListTable2_Accent6" | "ListTable3" | "ListTable3_Accent1" | "ListTable3_Accent2" | "ListTable3_Accent3" | "ListTable3_Accent4" | "ListTable3_Accent5" | "ListTable3_Accent6" | "ListTable4" | "ListTable4_Accent1" | "ListTable4_Accent2" | "ListTable4_Accent3" | "ListTable4_Accent4" | "ListTable4_Accent5" | "ListTable4_Accent6" | "ListTable5Dark" | "ListTable5Dark_Accent1" | "ListTable5Dark_Accent2" | "ListTable5Dark_Accent3" | "ListTable5Dark_Accent4" | "ListTable5Dark_Accent5" | "ListTable5Dark_Accent6" | "ListTable6Colorful" | "ListTable6Colorful_Accent1" | "ListTable6Colorful_Accent2" | "ListTable6Colorful_Accent3" | "ListTable6Colorful_Accent4" | "ListTable6Colorful_Accent5" | "ListTable6Colorful_Accent6" | "ListTable7Colorful" | "ListTable7Colorful_Accent1" | "ListTable7Colorful_Accent2" | "ListTable7Colorful_Accent3" | "ListTable7Colorful_Accent4" | "ListTable7Colorful_Accent5" | "ListTable7Colorful_Accent6"

注解

API 集:WordApi 1.3

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/90-scenarios/doc-assembly.yaml

await Word.run(async (context) => {
    const paragraph: Word.Paragraph = context.document.body.insertParagraph("Timeline", "End");
    paragraph.styleBuiltIn = "Heading2";
    const paragraph2: Word.Paragraph = context.document.body.insertParagraph("The Services shall commence on July 31, 2015, and shall continue through July 29, 2015.", "End");
    paragraph2.styleBuiltIn = "Normal";
    const paragraph3: Word.Paragraph = context.document.body.insertParagraph("Project Costs by Phase", "End");
    paragraph3.styleBuiltIn = "Heading2";
    // Note a content control with the title of "ProjectCosts" is added. Content will be replaced later.
    const paragraph4: Word.Paragraph = context.document.body.insertParagraph("<Add Project Costs Here>", "End");
    paragraph4.styleBuiltIn = "Normal";
    paragraph4.font.highlightColor = "#FFFF00";
    const contentControl: Word.ContentControl = paragraph4.insertContentControl();
    contentControl.title = "ProjectCosts";
    const paragraph5: Word.Paragraph = context.document.body.insertParagraph("Project Team", "End");
    paragraph5.styleBuiltIn = "Heading2";
    paragraph5.font.highlightColor = "#FFFFFF";
    const paragraph6: Word.Paragraph = context.document.body.insertParagraph("Terms of Work", "End");
    paragraph6.styleBuiltIn = "Heading1";
    const paragraph7: Word.Paragraph = context.document.body.insertParagraph("Contractor shall provide the Services and Deliverable(s) as follows:", "End");
    paragraph7.styleBuiltIn = "Normal";
    const paragraph8: Word.Paragraph = context.document.body.insertParagraph("Out-of-Pocket Expenses / Invoice Procedures", "End");
    paragraph8.styleBuiltIn = "Heading2";
    const paragraph9 : Word.Paragraph= context.document.body.insertParagraph("Client will be invoiced monthly for the consulting services and T&L expenses. Standard Contractor invoicing is assumed to be acceptable. Invoices are due upon receipt. client will be invoiced all costs associated with out-of-pocket expenses (including, without limitation, costs and expenses associated with meals, lodging, local transportation and any other applicable business expenses) listed on the invoice as a separate line item. Reimbursement for out-of-pocket expenses in connection with performance of this SOW, when authorized and up to the limits set forth in this SOW, shall be in accordance with Client's then-current published policies governing travel and associated business expenses, which information shall be provided by the Client Project Manager.", "End");
    paragraph9.styleBuiltIn = "Normal";
    // Insert a page break at the end of the document.
    context.document.body.insertBreak("Page", "End");

    await context.sync();
});

tableNestingLevel

获取 paragraph 的表级别。 如果段落不在表格中,它将返回 0。

readonly tableNestingLevel: number;

属性值

number

注解

API 集:WordApi 1.3

text

获取段落的文本。

readonly text: string;

属性值

string

注解

API 集:WordApi 1.1

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/get-paragraph-on-insertion-point.yaml

await Word.run(async (context) => {
  // The collection of paragraphs of the current selection returns the full paragraphs contained in it.
  const paragraph: Word.Paragraph = context.document.getSelection().paragraphs.getFirst();
  paragraph.load("text");

  await context.sync();
  console.log(paragraph.text);
});

uniqueLocalId

获取表示当前会话中段落标识符的字符串。 ID 采用不带大括号的标准 8-4-4-4-12 GUID 格式,并且在会话和共同创作者之间有所不同。

readonly uniqueLocalId: string;

属性值

string

注解

API 集:WordApi 1.6

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-annotations.yaml

// Registers event handlers.
await Word.run(async (context) => {
  eventContexts[0] = context.document.onParagraphAdded.add(paragraphChanged);
  eventContexts[1] = context.document.onParagraphChanged.add(paragraphChanged);

  eventContexts[2] = context.document.onAnnotationClicked.add(onClickedHandler);
  eventContexts[3] = context.document.onAnnotationHovered.add(onHoveredHandler);
  eventContexts[4] = context.document.onAnnotationInserted.add(onInsertedHandler);
  eventContexts[5] = context.document.onAnnotationRemoved.add(onRemovedHandler);
  eventContexts[6] = context.document.onAnnotationPopupAction.add(onPopupActionHandler);

  await context.sync();

  console.log("Event handlers registered.");
});

...

async function paragraphChanged(args: Word.ParagraphChangedEventArgs) {
  await Word.run(async (context) => {
    const results = [];
    for (let id of args.uniqueLocalIds) {
      let para = context.document.getParagraphByUniqueLocalId(id);
      para.load("uniqueLocalId");

      results.push({ para: para, text: para.getText() });
    }

    await context.sync();

    for (let result of results) {
      console.log(`${args.type}: ID ${result.para.uniqueLocalId}:-`, result.text.value);
    }
  });
}

方法详细信息

attachToList(listId, level)

将 paragraph 加入指定级别的现有 list。 如果 paragraph 无法加入 list 或已是 listItem,则无法执行此方法。

attachToList(listId: number, level: number): Word.List;

参数

listId

number

现有列表的 ID。

level

number

列表中的级别。

返回

注解

API 集:WordApi 1.3

clear()

清除对象的内容 Paragraph 。 用户可以对已清除的内容执行撤消操作。

clear(): void;

返回

void

注解

API 集:WordApi 1.1

示例

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Create a proxy object for the paragraphs collection.
    const paragraphs = context.document.body.paragraphs;

    // Queue a command to load the style property for all of the paragraphs.
    paragraphs.load('style');

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();

    // Queue a command to clear the contents of the first paragraph.
    paragraphs.items[0].clear();

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Cleared the contents of the first paragraph.');
});

closeUp()

删除段落前的任何空格。

closeUp(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

delete()

从文档中删除段落及其内容。

delete(): void;

返回

void

注解

API 集:WordApi 1.1

示例

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Create a proxy object for the paragraphs collection.
    const paragraphs = context.document.body.paragraphs;

    // Queue a command to load the text property for all of the paragraphs.
    paragraphs.load('text');

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();

    // Queue a command to delete the first paragraph.
    paragraphs.items[0].delete();

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Deleted the first paragraph.');
});

detachFromList()

如果此段落是列表项目的话,从列表中移出此段落。

detachFromList(): void;

返回

void

注解

API 集:WordApi 1.3

getAnnotations()

获取对此 Paragraph 对象设置的批注。

getAnnotations(): Word.AnnotationCollection;

返回

注解

API 集:WordApi 1.7

重要提示:由于基础服务的要求,此 API 需要 Microsoft 365 订阅才能正常工作。 有关详细信息,请参阅 GitHub 问题 4953

getComments()

获取与段落关联的注释。

getComments(): Word.CommentCollection;

返回

注解

API 集:WordApi 1.4

getContentControls(options)

获取段落中当前支持的内容控件。

getContentControls(options?: Word.ContentControlOptions): Word.ContentControlCollection;

参数

options
Word.ContentControlOptions

可选。 用于定义返回哪些内容控件的选项。

返回

注解

API 集:WordApi 1.5

重要提示: 如果在 options 参数中提供了特定类型,则仅返回受支持类型的内容控件。 请注意,使用通用 Word 的方法将引发异常与特定类型无关的 ContentControl。 随着时间的推移,可能会支持其他类型的内容控件。 因此,加载项应请求和处理特定类型的内容控件。

getHtml()

获取对象的 HTML 表示形式 Paragraph 。 在网页或 HTML 查看器中呈现时,格式将与文档的格式非常匹配,但不完全匹配。 此方法不会为不同平台上的同一文档返回完全相同的 HTML, (Windows、Mac、Word Web 等 ) 。 如果需要精确的保真度或跨平台的一致性,请使用 Paragraph.getOoxml() 返回的 XML 并将其转换为 HTML。

getHtml(): OfficeExtension.ClientResult<string>;

返回

注解

API 集:WordApi 1.1

示例

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Create a proxy object for the paragraphs collection.
    const paragraphs = context.document.body.paragraphs;

    // Queue a command to load the style property for all of the paragraphs.
    paragraphs.load('style');

    // 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 get the HTML of the first paragraph.
    const html = paragraphs.items[0].getHtml();

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Paragraph HTML: ' + html.value);
});

getNext()

获取下一个段落。 如果段落是最后一个段落,则引发 ItemNotFound 错误。

getNext(): Word.Paragraph;

返回

注解

API 集:WordApi 1.3

getNextOrNullObject()

获取下一个段落。 如果段落是最后一个段落,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

getNextOrNullObject(): Word.Paragraph;

返回

注解

API 集:WordApi 1.3

getOoxml()

获取对象的 Paragraph Office Open XML (OOXML) 表示形式。

getOoxml(): OfficeExtension.ClientResult<string>;

返回

注解

API 集:WordApi 1.1

示例

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Create a proxy object for the paragraphs collection.
    const paragraphs = context.document.body.paragraphs;

    // Queue a command to load the style property for the top 2 paragraphs.
    paragraphs.load({select: 'style', top: 2} );

    // 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 get the OOXML of the first paragraph.
    const ooxml = paragraphs.items[0].getOoxml();

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Paragraph OOXML: ' + ooxml.value);
});

getPrevious()

获取上一个段落。 如果段落是第一个段落,则引发 ItemNotFound 错误。

getPrevious(): Word.Paragraph;

返回

注解

API 集:WordApi 1.3

getPreviousOrNullObject()

获取上一个段落。 如果段落是第一个段落,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

getPreviousOrNullObject(): Word.Paragraph;

返回

注解

API 集:WordApi 1.3

示例

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Create a proxy object for the paragraphs collection.
    const paragraphs = context.document.body.paragraphs;

    // Queue a command to load the text property for all of the paragraphs.
    paragraphs.load('text');

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();

    // Queue commands to create a proxy object for the next-to-last paragraph.
    const indexOfLastParagraph = paragraphs.items.length - 1;
    const precedingParagraph = paragraphs.items[indexOfLastParagraph].getPreviousOrNullObject();

    // Queue a command to load the text of the preceding paragraph.
    precedingParagraph.load('text');

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    if (precedingParagraph.isNullObject) {
        console.log('There are no paragraphs before the current one.');
    } else {
        console.log('The preceding paragraph is: ' + precedingParagraph.text);
    }
});

getRange(rangeLocation)

获取整个段落或段落的起点/终点,作为一个范围。

getRange(rangeLocation?: Word.RangeLocation.whole | Word.RangeLocation.start | Word.RangeLocation.end | Word.RangeLocation.after | Word.RangeLocation.content | "Whole" | "Start" | "End" | "After" | "Content"): Word.Range;

参数

rangeLocation

whole | start | end | after | content | "Whole" | "Start" | "End" | "After" | "Content"

可选。 范围位置必须为 whole、 、 endstartafter、 或 。content

返回

注解

API 集:WordApi 1.3

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/get-paragraph-on-insertion-point.yaml

await Word.run(async (context) => {
  // Get the complete sentence (as range) associated with the insertion point.
  const sentences: Word.RangeCollection = context.document
    .getSelection()
    .getTextRanges(["."] /* Using the "." as delimiter */, false /*means without trimming spaces*/);
  sentences.load("$none");
  await context.sync();

  // Expand the range to the end of the paragraph to get all the complete sentences.
  const sentencesToTheEndOfParagraph: Word.RangeCollection = sentences.items[0]
    .getRange()
    .expandTo(
      context.document
        .getSelection()
        .paragraphs.getFirst()
        .getRange(Word.RangeLocation.end)
    )
    .getTextRanges(["."], false /* Don't trim spaces*/);
  sentencesToTheEndOfParagraph.load("text");
  await context.sync();

  for (let i = 0; i < sentencesToTheEndOfParagraph.items.length; i++) {
    console.log(sentencesToTheEndOfParagraph.items[i].text);
  }
});

getReviewedText(changeTrackingVersion)

根据所选内容获取审阅的文本 ChangeTrackingVersion

getReviewedText(changeTrackingVersion?: Word.ChangeTrackingVersion): OfficeExtension.ClientResult<string>;

参数

changeTrackingVersion
Word.ChangeTrackingVersion

可选。 值必须为 OR 。originalcurrent 默认值为 current

返回

注解

API 集:WordApi 1.4

getReviewedText(changeTrackingVersion)

根据所选内容获取审阅的文本 ChangeTrackingVersion

getReviewedText(changeTrackingVersion?: "Original" | "Current"): OfficeExtension.ClientResult<string>;

参数

changeTrackingVersion

"Original" | "Current"

可选。 值必须为 OR 。originalcurrent 默认值为 current

返回

注解

API 集:WordApi 1.4

getText(options)

返回段落的文本。 这不包括方程式、图形 (,例如图像、视频、绘图) 和标记各种内容 (的特殊字符,例如,对于内容控件、字段、注释、脚注、尾注) 。 默认情况下,隐藏的文字和标记为已删除的文字将被排除在外。

getText(options?: Word.GetTextOptions | {
            IncludeHiddenText?: boolean;
            IncludeTextMarkedAsDeleted?: boolean;
        }): OfficeExtension.ClientResult<string>;

参数

options

Word.GetTextOptions | { IncludeHiddenText?: boolean; IncludeTextMarkedAsDeleted?: boolean; }

可选。 定义最终结果是否应包括隐藏文本和标记为已删除的文本的选项。

返回

注解

API 集:WordApi 1.7

getTextRanges(endingMarks, trimSpacing)

使用标点符号和其他结束标记获取段落中的文本范围。

getTextRanges(endingMarks: string[], trimSpacing?: boolean): Word.RangeCollection;

参数

endingMarks

string[]

标点符号和其他结束标记为字符串数组。

trimSpacing

boolean

可选。 指示是否从范围集合中返回的范围的开头和结尾) 剪裁空格、制表符、分栏符和段落结束标记 (空格字符。 默认值指示 false 范围开头和结尾的空格字符包含在范围集合中。

返回

注解

API 集:WordApi 1.3

getTrackedChanges()

获取段落中对象的 TrackedChange 集合。

getTrackedChanges(): Word.TrackedChangeCollection;

返回

注解

API 集:WordApi 1.6

indent()

将段落缩进一级。

indent(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

indentCharacterWidth(count)

将段落缩进指定的字符数。

indentCharacterWidth(count: number): void;

参数

count

number

缩进的字符数。

返回

void

注解

API 集:WordApiDesktop 1.4

indentFirstLineCharacterWidth(count)

将段落首行缩进指定的字符数。

indentFirstLineCharacterWidth(count: number): void;

参数

count

number

首行缩进的字符数。

返回

void

注解

API 集:WordApiDesktop 1.4

insertAnnotations(annotations)

在此对象上 Paragraph 插入批注。

insertAnnotations(annotations: Word.AnnotationSet): OfficeExtension.ClientResult<string[]>;

参数

annotations
Word.AnnotationSet

要设置的批注。

返回

插入的批注标识符的数组。

注解

API 集:WordApi 1.7

重要提示:由于基础服务的要求,此 API 需要 Microsoft 365 订阅才能正常工作。 有关详细信息,请参阅 GitHub 问题 4953

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-annotations.yaml

// Adds annotations to the selected paragraph.
await Word.run(async (context) => {
  const paragraph: Word.Paragraph = context.document.getSelection().paragraphs.getFirst();
  const options: Word.CritiquePopupOptions = {
    brandingTextResourceId: "PG.TabLabel",
    subtitleResourceId: "PG.HelpCommand.TipTitle",
    titleResourceId: "PG.HelpCommand.Label",
    suggestions: ["suggestion 1", "suggestion 2", "suggestion 3"]
  };
  const critique1: Word.Critique = {
    colorScheme: Word.CritiqueColorScheme.red,
    start: 1,
    length: 3,
    popupOptions: options
  };
  const critique2: Word.Critique = {
    colorScheme: Word.CritiqueColorScheme.green,
    start: 6,
    length: 1,
    popupOptions: options
  };
  const critique3: Word.Critique = {
    colorScheme: Word.CritiqueColorScheme.blue,
    start: 10,
    length: 3,
    popupOptions: options
  };
  const critique4: Word.Critique = {
    colorScheme: Word.CritiqueColorScheme.lavender,
    start: 14,
    length: 3,
    popupOptions: options
  };
  const critique5: Word.Critique = {
    colorScheme: Word.CritiqueColorScheme.berry,
    start: 18,
    length: 10,
    popupOptions: options
  };
  const annotationSet: Word.AnnotationSet = {
    critiques: [critique1, critique2, critique3, critique4, critique5]
  };

  const annotationIds = paragraph.insertAnnotations(annotationSet);

  await context.sync();

  console.log("Annotations inserted:", annotationIds.value);
});

insertBreak(breakType, insertLocation)

在主文档的指定位置插入分隔符。

insertBreak(breakType: Word.BreakType | "Page" | "Next" | "SectionNext" | "SectionContinuous" | "SectionEven" | "SectionOdd" | "Line", insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After"): void;

参数

breakType

Word.BreakType | "Page" | "Next" | "SectionNext" | "SectionContinuous" | "SectionEven" | "SectionOdd" | "Line"

要添加到文档的分隔符类型。

insertLocation

before | after | "Before" | "After"

值必须为 OR 。beforeafter

返回

void

注解

API 集:WordApi 1.1

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/insert-line-and-page-breaks.yaml

Word.run(async (context) => {
  context.document.body.paragraphs.getFirst().insertBreak(Word.BreakType.line, "After");

  await context.sync();
  console.log("success");
});

insertCanvas(insertShapeOptions)

在文本前面插入浮动画布,其定位点位于段落的开头。

insertCanvas(insertShapeOptions?: Word.InsertShapeOptions): Word.Shape;

参数

insertShapeOptions
Word.InsertShapeOptions

可选。 画布的位置和大小。 默认位置和大小为 (0、0、300、200) 。

返回

注解

API 集:WordApiDesktop 1.2

insertContentControl(contentControlType)

Paragraph使用内容控件包装对象。

insertContentControl(contentControlType?: Word.ContentControlType.richText | Word.ContentControlType.plainText | Word.ContentControlType.checkBox | Word.ContentControlType.dropDownList | Word.ContentControlType.comboBox | Word.ContentControlType.buildingBlockGallery | Word.ContentControlType.datePicker | Word.ContentControlType.repeatingSection | Word.ContentControlType.picture | Word.ContentControlType.group | "RichText" | "PlainText" | "CheckBox" | "DropDownList" | "ComboBox" | "BuildingBlockGallery" | "DatePicker" | "RepeatingSection" | "Picture" | "Group"): Word.ContentControl;

参数

contentControlType

richText | plainText | checkBox | dropDownList | comboBox | buildingBlockGallery | datePicker | repeatingSection | picture | group | "RichText" | "PlainText" | "CheckBox" | "DropDownList" | "ComboBox" | "BuildingBlockGallery" | "DatePicker" | "RepeatingSection" | "Picture" | "Group"

可选。 要插入的内容控件类型。 必须是 richTextpicturecomboBoxbuildingBlockGalleryrepeatingSectiondatePickergroupplainTextcheckBoxdropDownList或 。 默认值为 richText

返回

注解

API 集:WordApi 1.1

注意:该 contentControlType 参数是在 WordApi 1.5 中引入的。 plainText WordApi 1.5 中添加了支持。 checkBox WordApi 1.7 中添加了支持。 dropDownList 并且 comboBox 在 WordApi 1.9 中添加了支持。 WordApiDesktop 1.3 中添加了对 buildingBlockGallerydatePickerpicturegroup、和repeatingSection的支持。

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/10-content-controls/insert-and-change-content-controls.yaml

// Traverses each paragraph of the document and wraps a content control on each with either a even or odd tags.
await Word.run(async (context) => {
  let paragraphs = context.document.body.paragraphs;
  paragraphs.load("$none"); // Don't need any properties; just wrap each paragraph with a content control.

  await context.sync();

  for (let i = 0; i < paragraphs.items.length; i++) {
    let contentControl = paragraphs.items[i].insertContentControl();
    // For even, tag "even".
    if (i % 2 === 0) {
      contentControl.tag = "even";
    } else {
      contentControl.tag = "odd";
    }
  }
  console.log("Content controls inserted: " + paragraphs.items.length);

  await context.sync();
});

insertFileFromBase64(base64File, insertLocation)

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

insertFileFromBase64(base64File: string, insertLocation: Word.InsertLocation.replace | Word.InsertLocation.start | Word.InsertLocation.end | "Replace" | "Start" | "End"): Word.Range;

参数

base64File

string

.docx 文件的 Base64 编码内容。

insertLocation

replace | start | end | "Replace" | "Start" | "End"

值必须为 replacestart、或 end

返回

注解

API 集:WordApi 1.1

如果要插入的文档包含 ActiveX 控件,则不支持插入, (可能在表单字段) 中。 请考虑将此类窗体字段替换为适合你的场景的内容控件或其他选项。

insertGeometricShape(geometricShapeType, insertShapeOptions)

在文本前面插入几何形状,其定位点位于段落的开头。

insertGeometricShape(geometricShapeType: Word.GeometricShapeType, insertShapeOptions?: Word.InsertShapeOptions): Word.Shape;

参数

geometricShapeType
Word.GeometricShapeType

要插入的形状的几何类型。

insertShapeOptions
Word.InsertShapeOptions

可选。 几何形状的位置和大小。 默认位置和大小 (0、0、100、100) 。

返回

注解

API 集:WordApiDesktop 1.2

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/45-shapes/group-ungroup.yaml

await Word.run(async (context) => {
  const body: Word.Body = context.document.body;
  body.clear();
  const lastParagraph: Word.Paragraph = body.paragraphs.getLast();

  // Inserts a text box.
  const textBoxOptions: Word.InsertShapeOptions = {
    top: 0,
    left: 0,
    height: 100,
    width: 100,
  };
  lastParagraph.insertTextBox("placeholder text", textBoxOptions);

  // Inserts a geometric shape.
  const geometricShapeOptions: Word.InsertShapeOptions = {
    height: 120,
    width: 120,
    left: 120,
  };
  lastParagraph.insertGeometricShape(Word.GeometricShapeType.star24, geometricShapeOptions);

  // Inserts a picture.
  const pictureOptions: Word.InsertShapeOptions = {
    top: 120,
    left: 60,
    height: 150,
    width: 150,
  };
  lastParagraph.insertPictureFromBase64(getPictureBase64(), pictureOptions);

  await context.sync();
});

insertGeometricShape(geometricShapeType, insertShapeOptions)

在文本前面插入几何形状,其定位点位于段落的开头。

insertGeometricShape(geometricShapeType: "LineInverse" | "Triangle" | "RightTriangle" | "Rectangle" | "Diamond" | "Parallelogram" | "Trapezoid" | "NonIsoscelesTrapezoid" | "Pentagon" | "Hexagon" | "Heptagon" | "Octagon" | "Decagon" | "Dodecagon" | "Star4" | "Star5" | "Star6" | "Star7" | "Star8" | "Star10" | "Star12" | "Star16" | "Star24" | "Star32" | "RoundRectangle" | "Round1Rectangle" | "Round2SameRectangle" | "Round2DiagonalRectangle" | "SnipRoundRectangle" | "Snip1Rectangle" | "Snip2SameRectangle" | "Snip2DiagonalRectangle" | "Plaque" | "Ellipse" | "Teardrop" | "HomePlate" | "Chevron" | "PieWedge" | "Pie" | "BlockArc" | "Donut" | "NoSmoking" | "RightArrow" | "LeftArrow" | "UpArrow" | "DownArrow" | "StripedRightArrow" | "NotchedRightArrow" | "BentUpArrow" | "LeftRightArrow" | "UpDownArrow" | "LeftUpArrow" | "LeftRightUpArrow" | "QuadArrow" | "LeftArrowCallout" | "RightArrowCallout" | "UpArrowCallout" | "DownArrowCallout" | "LeftRightArrowCallout" | "UpDownArrowCallout" | "QuadArrowCallout" | "BentArrow" | "UturnArrow" | "CircularArrow" | "LeftCircularArrow" | "LeftRightCircularArrow" | "CurvedRightArrow" | "CurvedLeftArrow" | "CurvedUpArrow" | "CurvedDownArrow" | "SwooshArrow" | "Cube" | "Can" | "LightningBolt" | "Heart" | "Sun" | "Moon" | "SmileyFace" | "IrregularSeal1" | "IrregularSeal2" | "FoldedCorner" | "Bevel" | "Frame" | "HalfFrame" | "Corner" | "DiagonalStripe" | "Chord" | "Arc" | "LeftBracket" | "RightBracket" | "LeftBrace" | "RightBrace" | "BracketPair" | "BracePair" | "Callout1" | "Callout2" | "Callout3" | "AccentCallout1" | "AccentCallout2" | "AccentCallout3" | "BorderCallout1" | "BorderCallout2" | "BorderCallout3" | "AccentBorderCallout1" | "AccentBorderCallout2" | "AccentBorderCallout3" | "WedgeRectCallout" | "WedgeRRectCallout" | "WedgeEllipseCallout" | "CloudCallout" | "Cloud" | "Ribbon" | "Ribbon2" | "EllipseRibbon" | "EllipseRibbon2" | "LeftRightRibbon" | "VerticalScroll" | "HorizontalScroll" | "Wave" | "DoubleWave" | "Plus" | "FlowChartProcess" | "FlowChartDecision" | "FlowChartInputOutput" | "FlowChartPredefinedProcess" | "FlowChartInternalStorage" | "FlowChartDocument" | "FlowChartMultidocument" | "FlowChartTerminator" | "FlowChartPreparation" | "FlowChartManualInput" | "FlowChartManualOperation" | "FlowChartConnector" | "FlowChartPunchedCard" | "FlowChartPunchedTape" | "FlowChartSummingJunction" | "FlowChartOr" | "FlowChartCollate" | "FlowChartSort" | "FlowChartExtract" | "FlowChartMerge" | "FlowChartOfflineStorage" | "FlowChartOnlineStorage" | "FlowChartMagneticTape" | "FlowChartMagneticDisk" | "FlowChartMagneticDrum" | "FlowChartDisplay" | "FlowChartDelay" | "FlowChartAlternateProcess" | "FlowChartOffpageConnector" | "ActionButtonBlank" | "ActionButtonHome" | "ActionButtonHelp" | "ActionButtonInformation" | "ActionButtonForwardNext" | "ActionButtonBackPrevious" | "ActionButtonEnd" | "ActionButtonBeginning" | "ActionButtonReturn" | "ActionButtonDocument" | "ActionButtonSound" | "ActionButtonMovie" | "Gear6" | "Gear9" | "Funnel" | "MathPlus" | "MathMinus" | "MathMultiply" | "MathDivide" | "MathEqual" | "MathNotEqual" | "CornerTabs" | "SquareTabs" | "PlaqueTabs" | "ChartX" | "ChartStar" | "ChartPlus", insertShapeOptions?: Word.InsertShapeOptions): Word.Shape;

参数

geometricShapeType

"LineInverse" | "Triangle" | "RightTriangle" | "Rectangle" | "Diamond" | "Parallelogram" | "Trapezoid" | "NonIsoscelesTrapezoid" | "Pentagon" | "Hexagon" | "Heptagon" | "Octagon" | "Decagon" | "Dodecagon" | "Star4" | "Star5" | "Star6" | "Star7" | "Star8" | "Star10" | "Star12" | "Star16" | "Star24" | "Star32" | "RoundRectangle" | "Round1Rectangle" | "Round2SameRectangle" | "Round2DiagonalRectangle" | "SnipRoundRectangle" | "Snip1Rectangle" | "Snip2SameRectangle" | "Snip2DiagonalRectangle" | "Plaque" | "Ellipse" | "Teardrop" | "HomePlate" | "Chevron" | "PieWedge" | "Pie" | "BlockArc" | "Donut" | "NoSmoking" | "RightArrow" | "LeftArrow" | "UpArrow" | "DownArrow" | "StripedRightArrow" | "NotchedRightArrow" | "BentUpArrow" | "LeftRightArrow" | "UpDownArrow" | "LeftUpArrow" | "LeftRightUpArrow" | "QuadArrow" | "LeftArrowCallout" | "RightArrowCallout" | "UpArrowCallout" | "DownArrowCallout" | "LeftRightArrowCallout" | "UpDownArrowCallout" | "QuadArrowCallout" | "BentArrow" | "UturnArrow" | "CircularArrow" | "LeftCircularArrow" | "LeftRightCircularArrow" | "CurvedRightArrow" | "CurvedLeftArrow" | "CurvedUpArrow" | "CurvedDownArrow" | "SwooshArrow" | "Cube" | "Can" | "LightningBolt" | "Heart" | "Sun" | "Moon" | "SmileyFace" | "IrregularSeal1" | "IrregularSeal2" | "FoldedCorner" | "Bevel" | "Frame" | "HalfFrame" | "Corner" | "DiagonalStripe" | "Chord" | "Arc" | "LeftBracket" | "RightBracket" | "LeftBrace" | "RightBrace" | "BracketPair" | "BracePair" | "Callout1" | "Callout2" | "Callout3" | "AccentCallout1" | "AccentCallout2" | "AccentCallout3" | "BorderCallout1" | "BorderCallout2" | "BorderCallout3" | "AccentBorderCallout1" | "AccentBorderCallout2" | "AccentBorderCallout3" | "WedgeRectCallout" | "WedgeRRectCallout" | "WedgeEllipseCallout" | "CloudCallout" | "Cloud" | "Ribbon" | "Ribbon2" | "EllipseRibbon" | "EllipseRibbon2" | "LeftRightRibbon" | "VerticalScroll" | "HorizontalScroll" | "Wave" | "DoubleWave" | "Plus" | "FlowChartProcess" | "FlowChartDecision" | "FlowChartInputOutput" | "FlowChartPredefinedProcess" | "FlowChartInternalStorage" | "FlowChartDocument" | "FlowChartMultidocument" | "FlowChartTerminator" | "FlowChartPreparation" | "FlowChartManualInput" | "FlowChartManualOperation" | "FlowChartConnector" | "FlowChartPunchedCard" | "FlowChartPunchedTape" | "FlowChartSummingJunction" | "FlowChartOr" | "FlowChartCollate" | "FlowChartSort" | "FlowChartExtract" | "FlowChartMerge" | "FlowChartOfflineStorage" | "FlowChartOnlineStorage" | "FlowChartMagneticTape" | "FlowChartMagneticDisk" | "FlowChartMagneticDrum" | "FlowChartDisplay" | "FlowChartDelay" | "FlowChartAlternateProcess" | "FlowChartOffpageConnector" | "ActionButtonBlank" | "ActionButtonHome" | "ActionButtonHelp" | "ActionButtonInformation" | "ActionButtonForwardNext" | "ActionButtonBackPrevious" | "ActionButtonEnd" | "ActionButtonBeginning" | "ActionButtonReturn" | "ActionButtonDocument" | "ActionButtonSound" | "ActionButtonMovie" | "Gear6" | "Gear9" | "Funnel" | "MathPlus" | "MathMinus" | "MathMultiply" | "MathDivide" | "MathEqual" | "MathNotEqual" | "CornerTabs" | "SquareTabs" | "PlaqueTabs" | "ChartX" | "ChartStar" | "ChartPlus"

要插入的形状的几何类型。

insertShapeOptions
Word.InsertShapeOptions

可选。 几何形状的位置和大小。 默认位置和大小 (0、0、100、100) 。

返回

注解

API 集:WordApiDesktop 1.2

insertHtml(html, insertLocation)

将 HTML 插入到段落中的指定位置。

insertHtml(html: string, insertLocation: Word.InsertLocation.replace | Word.InsertLocation.start | Word.InsertLocation.end | "Replace" | "Start" | "End"): Word.Range;

参数

html

string

要插入到段落中的 HTML。

insertLocation

replace | start | end | "Replace" | "Start" | "End"

值必须为 replacestart、或 end

返回

注解

API 集:WordApi 1.1

示例

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Create a proxy object for the paragraphs collection.
    const paragraphs = context.document.body.paragraphs;

    // Queue a command to load the style property for the top 2 paragraphs.
    // We never perform an empty load. We always must request a property.
    paragraphs.load({select: 'style', top: 2} );

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();

    // Queue a command to get the first paragraph.
    const paragraph = paragraphs.items[0];

    // Queue a command to insert HTML content at the end of the first paragraph.
    paragraph.insertHtml('<strong>Inserted HTML.</strong>', Word.InsertLocation.end);

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Inserted HTML content at the end of the first paragraph.');
});

insertInlinePictureFromBase64(base64EncodedImage, insertLocation)

将图片插入到段落中的指定位置。

insertInlinePictureFromBase64(base64EncodedImage: string, insertLocation: Word.InsertLocation.replace | Word.InsertLocation.start | Word.InsertLocation.end | "Replace" | "Start" | "End"): Word.InlinePicture;

参数

base64EncodedImage

string

要插入的 Base64 编码的图像。

insertLocation

replace | start | end | "Replace" | "Start" | "End"

值必须为 replacestart、或 end

返回

注解

API 集:WordApi 1.1

示例

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Create a proxy object for the paragraphs collection.
    const paragraphs = context.document.body.paragraphs;

    // Queue a command to load the style property for all of the paragraphs.
    paragraphs.load('style');

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();

    // Queue a command to get the first paragraph.
    const paragraph = paragraphs.items[0];

    const b64encodedImg = "iVBORw0KGgoAAAANSUhEUgAAAB4AAAANCAIAAAAxEEnAAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACFSURBVDhPtY1BEoQwDMP6/0+XgIMTBAeYoTqso9Rkx1zG+tNj1H94jgGzeNSjteO5vtQQuG2seO0av8LzGbe3anzRoJ4ybm/VeKEerAEbAUpW4aWQCmrGFWykRzGBCnYy2ha3oAIq2MloW9yCCqhgJ6NtcQsqoIKdjLbFLaiACnYyf2fODbrjZcXfr2F4AAAAAElFTkSuQmCC";

    // Queue a command to insert a base64 encoded image at the beginning of the first paragraph.
    paragraph.insertInlinePictureFromBase64(b64encodedImg, Word.InsertLocation.start);

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Added an image to the first paragraph.');
});

insertOoxml(ooxml, insertLocation)

在指定位置将 OOXML 插入段落中。

insertOoxml(ooxml: string, insertLocation: Word.InsertLocation.replace | Word.InsertLocation.start | Word.InsertLocation.end | "Replace" | "Start" | "End"): Word.Range;

参数

ooxml

string

要插入到段落中的 OOXML。

insertLocation

replace | start | end | "Replace" | "Start" | "End"

值必须为 replacestart、或 end

返回

注解

API 集:WordApi 1.1

insertParagraph(paragraphText, insertLocation)

在指定位置插入段落。

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

参数

paragraphText

string

要插入的段落文本。

insertLocation

before | after | "Before" | "After"

值必须为 OR 。beforeafter

返回

注解

API 集:WordApi 1.1

insertPictureFromBase64(base64EncodedImage, insertShapeOptions)

在文本前面插入浮动图片,其定位点位于段落的开头。

insertPictureFromBase64(base64EncodedImage: string, insertShapeOptions?: Word.InsertShapeOptions): Word.Shape;

参数

base64EncodedImage

string

要插入的 Base64 编码的图像。

insertShapeOptions
Word.InsertShapeOptions

可选。 图片的位置和大小。 默认位置为 (0, 0) ,默认大小是图像的原始大小。

返回

注解

API 集:WordApiDesktop 1.2

insertTable(rowCount, columnCount, insertLocation, values)

插入包含指定行数和列数的 table。

insertTable(rowCount: number, columnCount: number, insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After", values?: string[][]): Word.Table;

参数

rowCount

number

表格的行数。

columnCount

number

表格的列数。

insertLocation

before | after | "Before" | "After"

值必须为 OR 。beforeafter

values

string[][]

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

返回

注解

API 集:WordApi 1.3

insertText(text, insertLocation)

将文本插入到段落中的指定位置。

insertText(text: string, insertLocation: Word.InsertLocation.replace | Word.InsertLocation.start | Word.InsertLocation.end | "Replace" | "Start" | "End"): Word.Range;

参数

text

string

要插入的文本。

insertLocation

replace | start | end | "Replace" | "Start" | "End"

值必须为 replacestart、或 end

返回

注解

API 集:WordApi 1.1

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/insert-in-different-locations.yaml

await Word.run(async (context) => {
  // Replace the last paragraph.
  const range: Word.Range = context.document.body.paragraphs.getLast().insertText("Just replaced the last paragraph!", "Replace");
  range.font.highlightColor = "black";
  range.font.color = "white";

  await context.sync();
});

insertTextBox(text, insertShapeOptions)

在文本前面插入一个浮动文本框,其定位点位于段落的开头。

insertTextBox(text?: string, insertShapeOptions?: Word.InsertShapeOptions): Word.Shape;

参数

text

string

可选。 要插入文本框中的文本。

insertShapeOptions
Word.InsertShapeOptions

可选。 文本框的位置和大小。 默认位置和大小 (0、0、100、100) 。

返回

注解

API 集:WordApiDesktop 1.2

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/45-shapes/manage-shapes-text-boxes.yaml

await Word.run(async (context) => {
  // Inserts a text box at the beginning of the first paragraph in the header.
  const headerFooterBody: Word.Body = context.document.sections.getFirst().getHeader(Word.HeaderFooterType.primary);
  headerFooterBody.load("paragraphs");
  const firstParagraph: Word.Paragraph = headerFooterBody.paragraphs.getFirst();
  const insertShapeOptions: Word.InsertShapeOptions = {
    top: 0,
    left: 0,
    height: 100,
    width: 100
  };
  const newTextBox: Word.Shape = firstParagraph.insertTextBox("placeholder text", insertShapeOptions);
  newTextBox.select();
  await context.sync();

  console.log("Inserted a text box at the beginning of the first paragraph in the header.");
});

joinList()

将列表段落与此段落上方或下方最接近的列表联接。

joinList(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

load(options)

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

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

参数

options
Word.Interfaces.ParagraphLoadOptions

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

返回

load(propertyNames)

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

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

参数

propertyNames

string | string[]

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

返回

load(propertyNamesAndPaths)

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

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

参数

propertyNamesAndPaths

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

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

返回

next(count)

返回 Paragraph 表示下一段的对象。

next(count: number): Word.Paragraph;

参数

count

number

可选。 要向前移动的段落数。

返回

注解

API 集:WordApiDesktop 1.4

openOrCloseUp()

切换段落前的间距。

openOrCloseUp(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

openUp()

将段落前的间距设置为 12 磅。

openUp(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

outdent()

删除段落的一级缩进。

outdent(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

outlineDemote()

将标题级别样式 (标题 1 到标题 8) 应用到段落。

outlineDemote(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

outlineDemoteToBody()

通过应用“普通”样式将段落降级为正文文本。

outlineDemoteToBody(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

outlinePromote()

将之前的标题级别样式 (标题 1 到标题 8) 应用到段落。

outlinePromote(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

previous(count)

将上一段作为 Paragraph 对象返回。

previous(count: number): Word.Paragraph;

参数

count

number

可选。 要向后移动的段落数。

返回

注解

API 集:WordApiDesktop 1.4

reset()

删除手动段落格式(不使用样式应用的格式)。

reset(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

resetAdvanceTo()

将使用自定义列表级别的段落重置为原始级别设置。

resetAdvanceTo(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

search(searchText, searchOptions)

使用指定的搜索选项对对象范围执行 Paragraph 搜索。 搜索结果是对象的 Range 集合。

search(searchText: string, searchOptions?: Word.SearchOptions | {
            ignorePunct?: boolean;
            ignoreSpace?: boolean;
            matchCase?: boolean;
            matchPrefix?: boolean;
            matchSuffix?: boolean;
            matchWholeWord?: boolean;
            matchWildcards?: boolean;
        }): Word.RangeCollection;

参数

searchText

string

搜索文本。

searchOptions

Word.SearchOptions | { ignorePunct?: boolean; ignoreSpace?: boolean; matchCase?: boolean; matchPrefix?: boolean; matchSuffix?: boolean; matchWholeWord?: boolean; matchWildcards?: boolean; }

可选。 用于搜索的选项。

返回

注解

API 集:WordApi 1.1

select(selectionMode)

选择并在 Word UI 中导航到段落。

select(selectionMode?: Word.SelectionMode): void;

参数

selectionMode
Word.SelectionMode

可选。 选择模式必须为 select、 、startend select 为默认值。

返回

void

注解

API 集:WordApi 1.1

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/scroll-to-range.yaml

await Word.run(async (context) => {
  // If select is called with no parameters, it selects the object.
  context.document.body.paragraphs.getLast().select();

  await context.sync();
});

...

await Word.run(async (context) => {
  // Select can be at the start or end of a range; this by definition moves the insertion point without selecting the range.
  context.document.body.paragraphs.getLast().select(Word.SelectionMode.end);

  await context.sync();
});

select(selectionMode)

选择并在 Word UI 中导航到段落。

select(selectionMode?: "Select" | "Start" | "End"): void;

参数

selectionMode

"Select" | "Start" | "End"

可选。 选择模式必须为 select、 、startend select 为默认值。

返回

void

注解

API 集:WordApi 1.1

selectNumber()

选择列表中的编号或项目符号。

selectNumber(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

separateList()

将列表分隔为两个单独的列表。 对于编号的列表,新列表将从起始编号(通常为 1)开始重新编号。

separateList(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

set(properties, options)

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

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

参数

properties
Word.Interfaces.ParagraphUpdateData

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

options
OfficeExtension.UpdateOptions

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

返回

void

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/90-scenarios/multiple-property-set.yaml

await Word.run(async (context) => {
  const paragraph: Word.Paragraph = context.document.body.paragraphs.getFirst();
  paragraph.set({
    leftIndent: 30,
    font: {
      bold: true,
      color: "red"
    }
  });

  await context.sync();
});

...

await Word.run(async (context) => {
  const firstParagraph: Word.Paragraph = context.document.body.paragraphs.getFirst();
  const secondParagraph: Word.Paragraph = firstParagraph.getNext();
  firstParagraph.load("text, font/color, font/bold, leftIndent");

  await context.sync();

  secondParagraph.set(firstParagraph);

  await context.sync();
});

set(properties)

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

set(properties: Word.Paragraph): void;

参数

properties
Word.Paragraph

返回

void

space1()

将段落设置为单倍行距。

space1(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

space1Pt5()

将段落设置为 1.5 倍行距。

space1Pt5(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

space2()

将段落设置为双倍行距。

space2(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

split(delimiters, trimDelimiters, trimSpacing)

使用分隔符将段落拆分为多个子范围。

split(delimiters: string[], trimDelimiters?: boolean, trimSpacing?: boolean): Word.RangeCollection;

参数

delimiters

string[]

字符串数组形式的分隔符。

trimDelimiters

boolean

可选。 指示是否从范围集合中的范围剪裁分隔符。 默认值指示 false 分隔符包含在范围集合中返回的范围中。

trimSpacing

boolean

可选。 指示是否从范围集合中返回的范围的开头和结尾) 剪裁空格、制表符、分栏符和段落结束标记 (空格字符。 默认值指示 false 范围开头和结尾的空格字符包含在范围集合中。

返回

注解

API 集:WordApi 1.3

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/split-words-of-first-paragraph.yaml

await Word.run(async (context) => {
  const paragraph: Word.Paragraph = context.document.body.paragraphs.getFirst();
  const words = paragraph.split([" "], true /* trimDelimiters*/, true /* trimSpaces */);
  words.load("text");

  await context.sync();

  for (let i = 0; i < words.items.length; i++) {
    if (i >= 1) {
      words.items[i - 1].font.highlightColor = "#FFFFFF";
    }
    words.items[i].font.highlightColor = "#FFFF00";

    await context.sync();
    await pause(200);
  }
});

startNewList()

生成包含此 paragraph 的新 list。 如果此 paragraph 已是 listItem,则无法执行此方法。

startNewList(): Word.List;

返回

注解

API 集:WordApi 1.3

示例

// 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();
});

tabHangingIndent(count)

将悬挂缩进量设置为指定的制表位数。

tabHangingIndent(count: number): void;

参数

count

number

悬挂缩进的制表位数。

返回

void

注解

API 集:WordApiDesktop 1.4

tabIndent(count)

将段落的左缩进设置为指定的制表位数。

tabIndent(count: number): void;

参数

count

number

左侧缩进的制表位数。

返回

void

注解

API 集:WordApiDesktop 1.4

toJSON()

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

toJSON(): Word.Interfaces.ParagraphData;

返回

track()

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

track(): Word.Paragraph;

返回

untrack()

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

untrack(): Word.Paragraph;

返回

事件详细信息

onCommentAdded

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

在添加新批注时发生。

readonly onCommentAdded: OfficeExtension.EventHandlers<Word.CommentEventArgs>;

事件类型

注解

API 集:WordApi BETA (仅预览版)

onCommentChanged

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

更改注释或其回复时发生。

readonly onCommentChanged: OfficeExtension.EventHandlers<Word.CommentEventArgs>;

事件类型

注解

API 集:WordApi BETA (仅预览版)

onCommentDeleted

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

删除注释时发生。

readonly onCommentDeleted: OfficeExtension.EventHandlers<Word.CommentEventArgs>;

事件类型

注解

API 集:WordApi BETA (仅预览版)

onCommentDeselected

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

取消选择批注时出现。

readonly onCommentDeselected: OfficeExtension.EventHandlers<Word.CommentEventArgs>;

事件类型

注解

API 集:WordApi BETA (仅预览版)

onCommentSelected

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

选中批注时出现。

readonly onCommentSelected: OfficeExtension.EventHandlers<Word.CommentEventArgs>;

事件类型

注解

API 集:WordApi BETA (仅预览版)