Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update ooxml issue #5004

Open
XWANG0224 opened this issue Oct 25, 2024 · 1 comment
Open

update ooxml issue #5004

XWANG0224 opened this issue Oct 25, 2024 · 1 comment
Assignees
Labels
Area: Word Issue related to Word add-ins Needs: attention 👋 Waiting on Microsoft to provide feedback

Comments

@XWANG0224
Copy link

XWANG0224 commented Oct 25, 2024

Hi, I'm trying to set the starting number of page number in each sections by setting the ooxml ( because the api seems not support this function)
`const customizePageNumbering = async () => {
try{
await Word.run(async (context) => {
let docXML = context.document.body.getOoxml();
await context.sync();

            let parser = new DOMParser();
            let xmlDoc = parser.parseFromString(docXML.value, "text/xml");

            const ns = {'w': 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'};

            let sections = xmlDoc.getElementsByTagNameNS(ns.w, "sectPr");
            
            if(sections.length > 1){
                let firstSection = sections[0];
                let pgNumType = firstSection.getElementsByTagNameNS(ns.w, 'pgNumType');
                if(pgNumType.length === 0){
                    pgNumType = xmlDoc.createElementNS(ns.w, 'w:pgNumType');
                    pgNumType.setAttribute('w:start', '30');
                    console.log(pgNumType)
                    firstSection.appendChild(pgNumType);
                    console.log("after: ", firstSection);
                    console.log("Added pgNumType to first section");
                }
                else{
                    console.log("pgNumType already exists");
                    console.log(pgNumType.item(0));
                }
                let serializer = new XMLSerializer();
                let modifiedXML = serializer.serializeToString(xmlDoc);

                context.document.body.clear();
                context.document.body.insertOoxml(modifiedXML, Word.InsertLocation.replace);
                await context.sync();
            }
        });
    }
    catch (err) {
        console.error(err);
    }
}`

here is my code, in this example, I'm trying to set the page number of the first section start from 30, but it seems that I have already insert the <w:pgNumType w:start="30"/> in to the modifiedXML, but after I tried to insert the modifiedxml into the body, the pgNumType is deleted automatically, because when I checked the ooxml again, there is no pgNumType in the inserted xml, why is this happening? the code before the insertOoxml works just fine (I have loged the result and I'm sure about that)

@microsoft-github-policy-service microsoft-github-policy-service bot added the Area: Word Issue related to Word add-ins label Oct 25, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: attention 👋 Waiting on Microsoft to provide feedback label Oct 25, 2024
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Word Issue related to Word add-ins Needs: attention 👋 Waiting on Microsoft to provide feedback
Projects
None yet
Development

No branches or pull requests

2 participants