`context.document.body.insertOoxml` breaks documents, crashes word

吃可爱长大的小学妹 提交于 2020-01-12 09:58:20

问题


I know this is not a question, but I was sent here by Rick Kirkham from here, and apparently asking on SO is the way to file bugs for Microsoft products :-p

When I use insertOoxml with the 'replace' parameter, Word will insert extra content at the end. For example, when using the following code in Script Lab, with a new, empty word document:

$("#run").click(run);

function run() {
    Word.run(function (context) {
        var ooxml = context.document.body.getOoxml();
        return context.sync().then(function () {
            console.log(ooxml.value.length);
            context.document.body.insertOoxml(ooxml.value, Word.InsertLocation.replace);
            return context.sync();
        });
    });
}

Every time you trigger this code, the word document will acquire an additional paragraph at the end of the body. It gets crazier when the document ends in a content control: take a new document, insert a new rich text content control. Triggering run will duplicate the content control and insert it inside itself (so you have two content controls, where one is contained by the other). Clicking run a couple of times will create a lot of nested content controls and slow down Word to a crawl. Inserting a plain text content control and triggering 'run' twice will crash word (appears to be a null pointer dereference).

This is not a problem related to Script Lab, but using Script Lab is the easiest way to reproduce it.

Word version: 1703, build 7967.2139, 2016 MSO (16.0.7927.1020) 32-bit.

Expected behavior: Word does not crash and does not introduce extra content.

Okay so let's make this a question: how do I use a full-document insertOoxml(ooxml, 'replace') without breaking my documents?


回答1:


I verified with the newer build that Word does not crash, but an extra empty paragraph is indeed added. This bug was resolved yesterday and the fix will be available in the next month. Thanks!



来源:https://stackoverflow.com/questions/43857750/context-document-body-insertooxml-breaks-documents-crashes-word

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!