C# VSTO 字 AddIn 抛出值未落在预期错误范围内
我是 VSTO word Addin 的新手,最终目标是检查自定义文档属性是否存在。在线阅读所有可用文章,没有任何突破。
从此代码开始
public void chk()
{
if (this.Application.ActiveDocument.CustomDocumentProperties["ObjectType"].Value = 0)
{
MessageBox.Show("Please select an object");
}
}
这会引发错误
将代码修改为创建一个自定义文档属性对象,如下所示,它给了我同样的错误
if(this.Application.ActiveDocument.CustomDocumentProperties["ObjectType"].Value = 0)
public void chk()
{
dynamic properties = null;
properties = this.Application.ActiveDocument.CustomDocumentProperties;
properties.Add("Name",false,Office.MsoDocProperties.msoPropertyTypeString, "ObjectType");
properties.Add("LinkToContent",false, Office.MsoDocProperties.msoPropertyTypeBoolean,false);
properties.Add("Type",false,Office.MsoDocProperties.msoPropertyTypeNumber, 0);
if(this.Application.ActiveDocument.CustomDocumentProperties["ObjectType"].Value = 0)
{
MessageBox.Show("Please select an object");
}
}
请求您建议解决问题的步骤。如果需要更多信息,请告诉我。
I am new to VSTO word Addin,the end goal is to check if the custom document property exists.Read all the available articles online with no breakthrough.
Started of with this code
public void chk()
{
if (this.Application.ActiveDocument.CustomDocumentProperties["ObjectType"].Value = 0)
{
MessageBox.Show("Please select an object");
}
}
This throws the error
Value does not fall within bounds error
Modified the code to create a custom document property object as below and it gives me the same error on
if(this.Application.ActiveDocument.CustomDocumentProperties["ObjectType"].Value
= 0)
public void chk()
{
dynamic properties = null;
properties = this.Application.ActiveDocument.CustomDocumentProperties;
properties.Add("Name",false,Office.MsoDocProperties.msoPropertyTypeString, "ObjectType");
properties.Add("LinkToContent",false, Office.MsoDocProperties.msoPropertyTypeBoolean,false);
properties.Add("Type",false,Office.MsoDocProperties.msoPropertyTypeNumber, 0);
if(this.Application.ActiveDocument.CustomDocumentProperties["ObjectType"].Value = 0)
{
MessageBox.Show("Please select an object");
}
}
Requesting you to suggest the steps to fix the issue. Please let me know if more information is required.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以迭代所有属性并检查它们的名称,比较两种方法:
You can iterate over all properties and check their names, compare two approaches: