是否可以存储与Word文档中的特定表或单元格关联的隐藏元数据信息? [英] Is it possible to store hidden metadata information that is tied to a specific Table or Cell within a Word document?

查看:86
本文介绍了是否可以存储与Word文档中的特定表或单元格关联的隐藏元数据信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将元数据(基本上是唯一ID)与表格的每个单元格一起存储在Word文档中.当前,对于我正在开发的外接程序,我正在查询数据库,并使用检索到的数据在Word文档中构建表.

I am trying to store metadata (basically a unique id) along with each cell of a table in a Word document. Currently, for the add-in I'm developing, I am querying the database, and building a table inside the Word document using the data that is retrieved.

我希望能够将用户的任何编辑保存到文档中,并将其保存回数据库中.我最初的想法是在表中的每个单元格中存储一个唯一的ID,这样我就可以知道要更新的记录.我还想在每个单元格中存储某种"isChanged"标志,以便我可以知道哪些单元格已更改.我发现可以将所需的信息添加到单元格的"ID"属性中-但是,如果用户保存文档,将其关闭并重新打开,则不会保留该信息.然后,我尝试通过将数据添加到字段"集合中来存储数据-但这不起作用,并引发了运行时错误.这是我尝试的代码:

I want to be able to save any of the user's edits to the document, and persist it back to the database. My initial thought was to store a unique id along with each cell in the table so that I would be able to tell which records to update. I would also like to store some sort of "isChanged" flag within each cell so that I could tell which cells were changed. I found that I could add the needed information into the "ID" property of the cell - however, that information was not retained if the user saved the document, closed it, and re-opened it. I then tried storing the data by adding a data to the "Fields" collection - but that did not work and threw a runtime error. Here is the code that 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 runtime error "This command is not available".

那么,这有可能吗?还是我走错了方向?

So, is this possible at all? Or am I headed in the wrong direction?

谢谢.

推荐答案

使用"ContentControls"进行存储以存储所需的信息.我使用标题"字段存储唯一的ID,并使用标签"字段跟踪该字段是否已更改.请参阅此链接以获取更多信息: http://blogs.technet.com/gray_knowlton/archive/2010/01/15/associating-data-with-content-controls.aspx

Wound up using "ContentControls" to store the information I needed. I used the "Title" field to store the unique id, and the "tag" field to track whether the field had been changed or not. See this link for more info: http://blogs.technet.com/gray_knowlton/archive/2010/01/15/associating-data-with-content-controls.aspx

这篇关于是否可以存储与Word文档中的特定表或单元格关联的隐藏元数据信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆