急!!!麻烦技术同学看下!为什么调用Find.Execute(text)方法之后调用PasteHtml 一定会报错?

阅读次数 6

执行下面的代码,就能复现此问题! TypeError: Cannot create property 'message' on string 'service unavailable'

  let index = 0
  const textInterveal = setInterval(() => {
    if (index === 100) {
      clearInterval(textInterveal)
      setTimeout(async() => {
        const aboutContent = `

相关事件
我是文案` const findResult = await this.instance.WordApplication().ActiveDocument.Find.Execute('我是文案1') await this.instance.WordApplication().ActiveDocument.Find.ClearHitHighlight() if (findResult) { this.instance.Application.ActiveDocument.ActiveWindow.Selection.Range.PasteHtml({ HTML: aboutContent }) } }, 2000) } this.instance.Application.ActiveDocument.ActiveWindow.Selection.InsertAfter('我是文案' + index) index++ }, 50)
1 Answers

去掉延时2秒后正常,检查一下setInterval结合setTimeout写法是否正常image.png

去掉之后还是报错啊,请问你用的是哪个版本?

这个问题与sdk版本无关,pastehtml方法加上await调用再试试,看你之前的写法 pastehtml被InsertAfter插入到'我是文案100'阻塞了。

如果你那是正常的话,麻烦按照下面的步骤再试一次:执行代码, 然后切到别的程序,等待十秒左右切回浏览器,就会出现这个报错