Is it possible to store hidden metadata data tied to a specific table or cell in a Word document?

I am trying to save metadata (basically a unique identifier) ​​along with each table cell in a Word document. Currently, for the add-in that I am developing, I am querying a database and building a table inside a Word document using the received data.

I want to save any changes to the document in the document and save it back to the database. My initial thought was to store a unique identifier with each cell in the table so that I can determine which records need to be updated. I would also like to keep some kind of "isChanged" flag in each cell so that I can determine which cells have changed. I found that I can add the necessary information to the "ID" property of the cell, however this information was not saved if the user saved the document, closed it and reopened it. Then I tried to save the data by adding data to the "Fields" collection, but this did not work and threw a runtime error. Here is the code I tried:

object t1 = Word.WdFieldType.wdFieldEmpty;
object val = "myValue: " + counter;
object preserveFormatting = true;
tbl.Cell(i, j).Range.Fields.Add(tbl.Cell(i, j).Range, ref t1, ref val, ref preserveFormatting);

This compiles fine, but throws this run-time error "This command is not available."

So is this even possible? Or am I heading in the wrong direction?

Thanks in advance.

+5
source share
2 answers

Damage with ContentControls to store the information I need. I used the Title field to store the unique identifier and the Tag field to keep track of whether the field was changed or not. See this link for more information: http://blogs.technet.com/gray_knowlton/archive/2010/01/15/associating-data-with-content-controls.aspx

+1
source

"Word 2007 Document" XML, , . Word . , ().

Word, Excel 2003.

, , - "Word 2007 Document". " ". XML- , . Word , . , .

+1

All Articles