跳到主要内容

提取文档中所有段落的内容

代码示例

示例 1:获取段落的完整内容,不包含编号

async function example1() {
const data = [];
const count = await Application.ActiveDocument.Paragraphs.count;
for (let i = 1; i <= count; i += 1) {
const paragraph = await Application.ActiveDocument.Paragraphs.item(i);
const text = await paragraph.getTextContent();
data.push(text);
}
}

示例 2:获取段落的完整内容,包含编号(自 v8.0FP2 hotfix4 起支持)

async function example2() {
const data = [];
const count = await Application.ActiveDocument.Paragraphs.count;
for (let i = 1; i <= count; i += 1) {
const paragraph = await Application.ActiveDocument.Paragraphs.item(i);
const text = await paragraph.getTextContent(
undefined,
undefined,
{ listSymbol: true }
);
data.push(text);
}
}