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
681 stars 95 forks source link

getOoxml not working correctly on range #4101

Open junaid042 opened 9 months ago

junaid042 commented 9 months ago

In this delete that range is working prefect but when I getOoxml of this then its gives me full table xml I need only xml that range I am deleting

   await Word.run(async (context) => {
   const insertionPointRange = context.document.getSelection();
   const selectedRangeToEndOfCell = insertionPointRange.expandTo(context.document.getSelection().parentTableCellOrNullObject.body.getRange(Word.RangeLocation.end));
 // selectedRangeToEndOfCell.delete(); // deleting only range and working prefect 
   var openOOXML = selectedRangeToEndOfCell.getOoxml();
   await context.sync(); /
   console.log(openOOXML.value); // this is gives full table xml why?
 });

image

this is my document for quick test Get xml test.docx

this is Script Lab Gist

ElizabethSamuel-MSFT commented 9 months ago

@junaid042 Thanks, we'll take a look.

junaid042 commented 9 months ago

@ElizabethSamuel-MSFT I tested it in Ooxml this is getting main big table second td I want that range xml. when I have not small table inside big table then it is working fine

junaid042 commented 9 months ago

For now I got range xml that I needed using this

            const parser = new DOMParser();
            const Doc = parser.parseFromString(openOOXML.value, "application/xml");

            // Find the <w:tc> element
            const wtc = Doc4.getElementsByTagName("w:tc")[0];

            // Extract the full <w:tc> element with its tags
            const tcContent = wtc.innerHTML;

            // Log the result
             console.log(tcContent);
ElizabethSamuel-MSFT commented 9 months ago

@junaid042 Looks like this could be a bug. Assigning to the product team to investigate.

zhenhuangMSFT commented 8 months ago

Hi @junaid042 , May I ask on which platform are you having the issue? Thanks!

junaid042 commented 8 months ago

desktop image

junaid042 commented 8 months ago

Hi @zhenhuangMSFT this is getting correct range xml but with main table second td. I managed this with some effort but this is a bug.

xuruiyao-msft commented 8 months ago

@junaid042 I test some cases with the code below: const select = context.document.getSelection(); const ooxml = select.getOoxml(); await context.sync(); console.log(ooxml.value);

I manually select the inner table only, get the ooxml, but the xml still contains the main table second td,

image

I created a work item(8801858) to track this issue. Any progress we'll sync with you. Thanks again to reach out to us.