OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
674 stars 95 forks source link

Content Control insertOoxml may not preserve numbering style in Office Online #4684

Open whekin opened 3 months ago

whekin commented 3 months ago

Provide required information needed to triage your issue

Your Environment

Expected behavior

Same as in the desktop version of Word. Also, same as if working with documents with simpler numbering style.

Current behavior

When working with the example document I get the following behavior in Word Online. Before inserting ooxml: image

After inserting ooxml: image

Link to the document (onedrive)

When using simpler numbering styles ooxml inserts as expected.

Steps to reproduce

Code to insert ooxml:

await Word.run(async (context) => {
    const selection = context.document.getSelection();
    const cc = selection.parentContentControl.load();
    cc.cannotDelete = false;

    await context.sync();

    const ooxml = cc.getOoxml();

    await context.sync();

    cc.getRange().insertOoxml(ooxml.value, "Replace");

    await context.sync();
});

Provide additional details

  1. The example document already has a content control over 1.1 section
  2. Selecting it and executing the code results in the issue in Word Online

Additionally, there inconsistent behavior of getOoxml in Word Online and Word for Mac. On Mac, the document body I get the w:sdt itself, while in Word Online I get the contents of w:sdtContent. The the images below I executed this code:

 await Word.run(async (context) => {
    const selection = context.document.getSelection();

    const cc = selection.parentContentControl.load();

    await context.sync();

    const ooxml = cc.getOoxml();

    await context.sync();

    const ccDocument = new DOMParser().parseFromString(ooxml.value, "text/xml");

    const document = ccDocument.getElementsByTagName("w:document")[0];

    const body = document.children[0];

    console.log(body);
});

Logs from Mac: image

Logs from Word Online: image

Context

I'm developing an add-in for document automation. I want to toggle (hide/unhide) sections in a big list though the add-in. I've come up with a solution using content controls over each section, and then inserting ooxml with , tags in places. I've seen "hidden" property in the preview word api, I even tested it, but it left the content control itself (and section title) visible for some reason. I need a solution that I can use now.

microsoft-github-policy-service[bot] commented 3 months ago

Thank you for letting us know about this issue. We will take a look shortly. Thanks.

shanshanzheng-dev commented 3 months ago

Hi @whekin Thanks for reporting this issue. Could you share us public doc link since I can not repro your problem with my doc and I can't edit your onedrive link? Thanks.

whekin commented 3 months ago

Hey @shanshanzheng-dev, here is the file: numbering-style-issue-example.docx

Also, editable version on onedrive: link

shanshanzheng-dev commented 3 months ago

Hi @whekin Thanks for providing this doc link, we'll be looking into this issue, and we'll report back if we have a suggestion for you, Thanks.

aeturneus commented 2 months ago

@shanshanzheng-dev the same example document has numbering rendering issues in WOPI , uncertain if related, reported here https://github.com/OfficeDev/office-js/issues/4698#issuecomment-2245378359