1
votes

Code to get ooxml in wordjs generates one extra empty paragraph. But in my Add-in I need to getOoxml -> modify it -> and then replace it using insertOoxml. But this causes each replace operation to add one extra paragraph.

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);
});

So in word I have only 2 paragraphs (I have showed hidden paragraphs to be certain):

111111111

222222222

Which is returned as:

<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"/>

Here is the empty paragraph from the above XML result:

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

I'm using Word 2016, docx file. And OfficeJs lib hosted here: https://appsforoffice.microsoft.com/lib/1/hosted/Office.js

1
I am trying to read the data from ooxml object in OfficeJs within angular. I am unable to do that, can you help me on this? - Khawaja Asim

1 Answers

0
votes

this issue was fixed. what build are you using? are you using the latest Office update?