【发布时间】:2017-02-22 12:05:25
【问题描述】:
几天前我创建了this,在其中我需要有关如何将自定义属性添加到所述文档的帮助。
首先,我正在运行 Word 1701(7766.2047)。
假设我有一个方法,我在其中返回一个所说的自定义属性。首先,我会检查是否已经创建了自定义属性。我会用一个简单的 getItemOrNullObject(key) 和.. 来做到这一点。
- 如果返回 null 然后简单地创建它并返回它
- 否则退回
据我了解,我需要执行 return context.sync().then 以使对象实际加载数据?我是否做了太多的 return context.sync() 调用?
Word.run(function(context) {
var customDocProps = context.document.properties.customProperties;
context.load(customDocProps);
return context.sync()
.then(function() {
var temp = customDocProps.getItemOrNullObject("X");
return context.sync()
.then(function() {
if (!temp) {
context.document.properties.customProperties.add("X", 1234);
temp = customDocProps.getItemOrNullObject("X");
return context.sync()
.then(function() {
return temp;
});
} else {
return temp;
}
});
});
});
以下代码在开始时向我抛出“ReferenceError: 'Word' is undefined”,但如果我对其进行调试,它会在中断之前运行
var customDocProps = context.document.properties.customProperties;
context.load(customDocProps);
return context.sync().{....}
还有一个问题。假设我想更新我的自定义属性,会:
Word.run(function (context) {
context.document.properties.customProperties.add("X", 56789);
return context.sync();
});
用新值覆盖旧值?
如果你读到这里,谢谢!任何帮助表示赞赏。 干杯!
【问题讨论】:
标签: javascript ms-word ms-office office-js office-addins