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.
source
share