如何更改word文档中的变量名称?
我的应用程序允许用户将信息插入文档(使用文档属性和变量)。其中一部分还在于他们应该能够调整之前输入的值。更改文档属性的 Name
和 Value
没有问题,但显然 variable Name
有一个 get 属性仅,无设置属性。这就是我分配变量的方式:
object v = _name;
Variables.Add(_sName, ref v);
这就是我理想的更改变量的方式。
var.Name = newName;
但它给出了一个错误:
无法将属性或索引器“Word.Variable.Name”分配给 - 它是只读的
我能想到的唯一选择是删除变量并创建一个新变量与更新的值。但这真的是我唯一的选择吗?
My application allows the user to insert information into a document (using document properties and variables). Part of this is also that they should be able to adjust the values they have previously entered. Changing the Name
and Value
of a document property is no problem, but apparently the variable Name
has a get property only, no set property. This is how I'm assigning a variable:
object v = _name;
Variables.Add(_sName, ref v);
This is how I'd ideally change the variable.
var.Name = newName;
But it gives an error saying:
Property or indexer 'Word.Variable.Name' cannot be assigned to -- it is read only
The only option I can think of is deleting the variable and creating a new one with the updated values. But is that really my only option?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我继续通过简单地更改文档属性的名称和值来解决这个问题,同时删除变量并使用更新的值创建新变量。据我所知,这是唯一的方法。
I went ahead and solved it by simply changing the name and value of the document property, but also removing the variables and creating new ones with the updated values. As far as I know that's the only way to go about it.