Open-XML-SDK icon indicating copy to clipboard operation
Open-XML-SDK copied to clipboard

generated paraId values replaced with msword app

Open Artyom-Petukhov opened this issue 4 years ago • 5 comments

Description

Paragraph have property ParagraphId

        /// <summary>
        /// <para>paraId, this property is only available in Office 2010 and later.</para>
        /// <para>Represents the following attribute in the schema: w14:paraId</para>
        /// </summary>
        /// <remark>
        /// xmlns:w14=http://schemas.microsoft.com/office/word/2010/wordml
        /// </remark>

#pragma warning disable CS0618 // Type or member is obsolete

        [SchemaAttr(52, "paraId")]
#pragma warning restore CS0618 // Type or member is obsolete

        public HexBinaryValue? ParagraphId
        {
            get => GetAttribute<HexBinaryValue>();
            set => SetAttribute(value);
        }

According to the issue #245 I tried to generate paraId for paragraphs (and set textId = "77777777" to respect spec). When I open generated docx with MS Word 2016/365 - it's Ok, no errors, no warnings etc.

Generated docx is protected from modifications, I can only add/modify/remove comments to it.

After adding new comment to document and saving it - all paraId values replaced by MS Word to new values (in document.xml). When I open this docx with MS Word again, add new comment and save - paraId values remain the same.

QUESTION How generate paraId values for paragraphs so that the MS Word does not change their values? My app needs these IDs not to change after adding comments.

Example generated docx contains: <w:p w14:paraId="1AD69E69" w14:textId="77777777" ...

after adding comment via ms word (after 1st "edit" and all subsequent): <w:p w14:paraId="6B99AEB6" w14:textId="77777777" ...

Artyom-Petukhov avatar Apr 23 '21 04:04 Artyom-Petukhov

I believe that it's time to add the method of paraId generation for paragraphs to the SDK regardless whether the comments have been added to a docx or not because office 365 does this way already.

Artyom-Petukhov avatar Apr 23 '21 14:04 Artyom-Petukhov

@Artyom-Petukhov, was this issue resolved? Did you find out why the paraId values were changed?

@twsouthwick and @tomjebo, did you look into this? Under what conditions does Word change the paraId values? Would Word change values that comply with the specification?

In one of my use cases, it is extremely important to understand whether I can rely on the paraId values being unique and stable.

ThomasBarnekow avatar Jun 16 '21 09:06 ThomasBarnekow

@Artyom-Petukhov @ThomasBarnekow Can either of you provide a simple sample to generate a document that causes Word to have this behavior? paraId is literally a random number between 1 and 0x7FFFFFFF. I have tried to test the limits of paraId and textId and am not able to cause the behavior in Word or Word web app that you describe. Word will replace paraId's that fall outside the limit but it is fine allowing edit of the document before saving. Also if you can please provide the version of Word desktop that you're testing?

tomjebo avatar Jul 09 '21 23:07 tomjebo

@tomjebo, I can't provide an example. I am just interested to understand Word's behavior in this regard as I also depend on w14:paraId values to not be changed.

ThomasBarnekow avatar Jul 10 '21 07:07 ThomasBarnekow

I'm facing similar behavior with office js. Whenever I get OOXML, it always has different paraId values.

But when I open the document.xml in editor, it has the correct and always the same paraId values

Sample code is on click:

      var range = context.document.getSelection();
      var ooxml = range.getOoxml();
      await context.sync();
      const paragraph = context.document.body.insertParagraph(ooxml.value, Word.InsertLocation.end);

On a click, get the selected text and display XML at the end of the document. If I click the button multiple times, the XML always has different paraId attributes.

PawelStadnicki avatar Feb 07 '23 15:02 PawelStadnicki