如何更改word文档中的变量名称?

发布于 2024-09-06 20:35:45 字数 484 浏览 1 评论 0原文

我的应用程序允许用户将信息插入文档(使用文档属性和变量)。其中一部分还在于他们应该能够调整之前输入的值。更改文档属性的 NameValue 没有问题,但显然 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一城柳絮吹成雪 2024-09-13 20:35:46

我继续通过简单地更改文档属性的名称和值来解决这个问题,同时删除变量并使用更新的值创建新变量。据我所知,这是唯一的方法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文