没有正确获取文档结尾位置

阅读次数 3

使用这段代码没有正确获取文档结尾位置,在段落中间就截断了是为什么? const app = instance.Application // 返回一个 Range 对象 const ContentRange = await app.ActiveDocument.Content
const End = await ContentRange.End
const Range = await instance.Application.ActiveDocument.Range.SetRange(End, End)
// 选区对象
await Range.PasteHtml({ HTML: html})<img src="https://solution-community.wps.cn/uploads/post/5te2wKLwkiJ.png" alt="image.png"/>

1 Answers

因为使用await app.ActiveDocument.Content的时候wps中的内容没有加载完,可以加一个延时方法

await this.state.editor.ready(); const app = this.state.editor.Application;

await this.delay(500); // 延迟 500ms 让内容完全渲染

const contentRange = await app.ActiveDocument.Content; const End = await contentRange.End; console.log('End', End);