简体   繁体   中英

How to export a complex element in a doc showing just a property and keeping all other information?

I need to import and export some documents from my web app written in .net-core to docx and viceversa: the users should be able to export, modify offline, and import back. Currently I am using OpenXml-PowerTools to export.

The problem is that there are dynamic contents that show the current value of some fields in the database so I should be able to export the document showing a face value (for instance an amount of money) and when importing back I should be able to recall the original reference (which is an object containing an expression and operations, like "sum_db_1 + sum_db_2" and info about the formatting of numbers and so on). Of course if needed everything can be treated as a String instead of a complex object.

In the original document the face value is shown (a text or an amount) while the original formula is stored like in this xml:

 <reuse-link reuse="reuse-link">
  <reuse-param name="figname" value="exp_sum_n"></reuse-param>
  <reuse-param name="format" value="MC"></reuse-param>
</reuse-link>

In short, I need the possibility to export a complex object in Word that shows the face value and keeps somewhere also the other additional fields of the original object so they can be retrieved once imported back. The possibility of editing the "complex" values is not foreseen.

How can I achieve this?

I tried to negotiate with customers explaining they should only edit online but they are not flexible to change their internal workflow that foresee an exchange of the document between various parties.

Thank you in advance for your help.

I suggest you use one or more Custom XML Parts to store whatever additional information you need. You will probably need to create a naming convention that will allow you to relate elements/attributes in those Parts to the "face values" (however they may be expressed).

A Custom XML Part can store any XML (the content does have to be valid XML). As long as you create them, and the necessary relationships, in the .docx or Flat OPC format .xml file, the Parts should survive normal use - ie the user would have to do something unusual to delete them.

You could also store the information in Word document variables, but Custom XML Parts look like a better fit to your scenario.

(Sorry, I am not yet allowed to post comments or respond to them here).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM