5

Is there a way to store additional data for a paragraph, that would be persisted after user opens and saves a document in MS Word.

Ive been using CusotmXML for this, but it turns out that this is no logner possible due to the fact that MS-Word strips all CusotmXML elements from the document structure.

Every single paragraph or a table has an ID that I would like to "pair back" to my data-source. So later when I read the docx again I can identify origins of every unchanged paragraph/table in the document.

aerkain
  • 592
  • 1
  • 4
  • 16

3 Answers3

1

A possibility would be to insert a SET field. This creates a bookmark in the document to which you can assign information. There's no way to protect it from the user removing it, however. A DATA field might also be a possibility.

Unlike "vanish" (which I believe is equivalent to "hidden" font format) the information would not display if the user is in the habit of displaying non-printing information. It will display, however, if the user toggles on field codes (Alt+F9).

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
0

You can have a divId on a paragraph, and in xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" there are attributes w14:textId and w14:paraId.

For example:

<w:p w14:textId="81a184ad" w14:paraId="81a184ad" >
  <w:pPr>
    <w:divId w:val="124349312"/>

See [MS-Docx] for details.

Alternatively, have a look at content controls, which you can wrap around paragraphs and tables (or put inside them). These have an ID property; they also let you store arbitrary text in their tag property. The string is limited in length to something like 120 chars.

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
  • Ive just found out that when I open generated document in MS-Word and save it to disk. Word does not persists paraId,textId Attribute and divId element. – aerkain Aug 16 '13 at 14:11
  • Content controls are visible to user, arent they?. My additional data must not have any effect on what the user is looking at. – aerkain Aug 16 '13 at 14:19
  • Re your first comment, I guess you need to be clear on which versions of Word you are dealing with (eg 2007, 2010, 2013). Re your second, yes, the control is visible (add the Developer menu, then insert one in your docx to see); you'll need to try it to decide whether you're OK with the user interface. – JasonPlutext Aug 16 '13 at 21:02
  • Thank you. My perspective is that it must be persistent all the times. Completely independent on the MSWord version users are having. – aerkain Aug 19 '13 at 08:17
  • If any version of MS-Word would strip my hidden data its not a solution for me, since I do not control what version of MS-Word users have. – aerkain Aug 21 '13 at 11:26
0

A rather noddy solution, but have you cosidered using a custom run for your data and hiding it from displaying using Vanish

<w:rPr>
   <w:vanish />
</w:rPr>

Adding vanish to run properties will hide the run from displaying and you might use this to store custom data with out affecting the output of the document.

Flowerking
  • 2,551
  • 1
  • 20
  • 30
  • Thank you, I did considered this, but frankly this is kinda strange solution (moving from CustomXML), but maybe it is the only one suitable for my needs. – aerkain Aug 19 '13 at 08:19
  • Like you mentioned in the question, `CustomXML` is taken off from Open XML specification after a patent case. I agree that there might be some way to store custom data for programmatic use! – Flowerking Aug 19 '13 at 08:31
  • There is a slight problem with this solution. If the user has turn on "show hidden text" he/she will see this markups. So its still far from ideal solution, but still the closest one I know for now. – aerkain Aug 19 '13 at 09:05
  • I have a similar requirement. Did you find any suitable solution. @aerkain – user3282758 Aug 22 '14 at 16:10