从Word中获取文本时出现Word加载项问题

时间:2017-07-04 10:32:26

标签: office-js word-addins

我正在写一个Word加载项。 我想抓住单词中的Text并将文本转换为Html。 我使用了官方文档中的示例。 https://dev.office.com/reference/add-ins/word/body

基本上它有效,但有一个问题我无法解决。 每次我从Word中获取文本时,程序会冻结一秒钟。 (时间取决于文件的长度) 这个打嗝让Word无法使用。 我定期抓住文本进行一些分析。 我需要一种方法来获取文本并在后台将其转换为Html而不会冻结。

// Run a batch operation against the Word object model.
return Word.run(function (context)
{
    var body = context.document.body;
    var content = body.getHtml();

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    return context.sync().then(function () {
        console.log(content.value);
        return content.value;
    });
});

0 个答案:

没有答案