1
我正在开发一个excel VSTO加载项,在附加组件I中构建一些工作表以便稍后处理它们。如果工作簿是使用我的加载项进行构建的,或者不对其执行操作,那么以后我想知道用户打开并优化工作簿的时间。为此,我尝试使用CustomDocumentProperties。设置异常excel工作簿的自定义文档属性
我面临两个问题:
- Visual Studio调试器不评价DocumentProperties变量的孩子,我不能对其进行检查。
- 当我尝试通过调用DocumentProperties.Add创建一个新的DocumentPropertiy时,我得到一个ArgumentException,指出该值不在范围内。
函数调用构建工作簿:
public void InitWorkbook()
{
workingBook = Globals.Factory.GetVstoObject(Application.ActiveWorkbook);
var dps = (DocumentProperties)workingBook.CustomDocumentProperties;
if (!customDocumentPropertyExist("validctcwb", dps))
{
// some sheet creation and listobject creation
dps.Add("validctcwb", false);
}
}
bool customDocumentPropertyExist(string name, DocumentProperties dps)
{
foreach (DocumentProperty p in dps)
{
if (p.Name == name)
{
return true;
}
}
return false;
}
预先感谢您的宝贵帮助。
谢谢你的回答,没有它工作得很好。 propertyValue对于Add方法不是可选参数?为什么需要我提供他们才能添加房产? –
当'linkToContent'(第二个参数)为'false'时,则需要该值。如果“true”,则需要'linkSource'。请参阅MSDN:https://msdn.microsoft.com/en-us/library/microsoft.office.core.documentproperties.add.aspx – adPartage
好的,谢谢你很清楚我知道。 –