在wordjs中获取ooxml的代码会生成一个额外的空段落。但是在我的加载项中,我需要getOoxml->修改它->,然后使用insertOoxml替换它。但这导致每个替换操作添加一个额外的段落。

return new Promise((resolve, reject) => {
    // Run a batch operation against the Word object model.
    Word.run(function (context) {

        // Create a proxy object for the document body.
        var body = context.document.body;
        let paras: Word.ParagraphCollection = body.paragraphs.load();

        // Queue a command to get the current selection.
        // Create a proxy range object for the selection.
        let ooxml = body.getOoxml();
        // Queue a commmand to load the text in document body.
        context.load(body, 'text');

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

                let text = body.text;
                resolve({
                    text: text,
                    ooxml: ooxml.value,
                })
            });
    })
    .catch(this.errorHandler);
});


因此,用词来说,我只有2个段落(可以肯定地说出隐藏的段落):


  111111111
  
  222222222


返回为:

<w:p w:rsidR="003431F8" w:rsidRDefault="003431F8" w:rsidP="003431F8"><w:r><w:t>111111111</w:t></w:r></w:p><w:p w:rsidR="003431F8" w:rsidRDefault="003431F8" w:rsidP="003431F8"><w:r><w:t>222222222</w:t></w:r></w:p><w:p w:rsidR="00000000" w:rsidRDefault="003431F8"/>


这是上述XML结果中的空段:

<w:p w:rsidR="00000000" w:rsidRDefault="003431F8"/>


我正在使用Word 2016,docx文件。 OfficeJs lib托管在这里:https://appsforoffice.microsoft.com/lib/1/hosted/Office.js

最佳答案

此问题已解决。您正在使用什么版本?您是否在使用最新的Office更新?

10-08 17:19