gpt4 book ai didi

javascript - 对面平台无法识别 Office.js 绑定(bind)(Office Online 与 Office Desktop)

转载 作者:行者123 更新时间:2023-12-03 14:31:45 29 4
gpt4 key购买 nike

我们正在为 Excel 和 Word 开发 javascript Office 插件。我们的用户将使用 Office Desktop 和 Office Online。

当用户在加载项中创建新记录时,我们会在当前具有焦点的范围上创建绑定(bind)。绑定(bind)正在创建并且看起来正常,但如果用户在 Office Desktop 中创建绑定(bind),然后在 Office Online 中打开该文档,则无法识别该绑定(bind)。反之亦然,如果绑定(bind)是在 Office Online 中创建的,则稍后 Desktop 不会识别它们。

有更好的方法吗?

请参阅下面的代码,了解 Excel 中的示例:

addNote() {
try {
Excel.run((ctx) => {
const selectedRange = ctx.workbook.getSelectedRange();
selectedRange.load('address');

return ctx.sync().then(() => {
const currentAddress = selectedRange.address;
this.setState({ currentAddress });

const bindingName = `SymphonyBinding_${newGuid()}`;
const myBindings = Office.context.document.bindings;
this.setState({ bindingName });
myBindings.addFromNamedItemAsync(currentAddress, 'matrix', { id: bindingName },
(result) => {
if (result.status === 'succeeded') {
this.setState({ bindingName: result.value.id });
meow.raise({ name: 'create-new-note', context: { tags: [result.value.id] } });
} else {
this.setState({ bindingName: 'could not bind' });
}
});
});
});
} catch (error) {
handleError('Office Add-In', error, error.message);
}
}

这是识别绑定(bind)的代码:

showNoteRequested({ context }) {
const { note } = context;
note.tags.forEach((tag) => {
if (tag.name.indexOf('SymphonyBinding_') !== -1) {
this.setState({ bindingName: tag.name }, this.selectRange);
}
});
}

selectRange() {
const { bindingName } = this.state;
try {
Excel.run((ctx) => {
const foundBinding = ctx.workbook.bindings.getItem(bindingName);
const myRange = foundBinding.getRange();
myRange.select();
myRange.load('address');
return ctx.sync().then(() => {
const currentAddress = myRange.address;
this.setState({ currentAddress });
});
});
} catch (error) {
handleError('Office Add-In', error, error.message);
}
}

最佳答案

以下绑定(bind)创建代码与 addNode 中的代码等效吗?当文件在 Excel Online 版本 16.0.9229.5030 中加载时,它似乎对我来说工作正常。

function run() {
return Excel.run(function (ctx) {
const selectedRange = ctx.workbook.getSelectedRange();
selectedRange.load('address');

return ctx.sync().then(() => {
const currentAddress = selectedRange.address;
const bindingName = 'SymphonyBinding_{493332C3-F66B-41BF-B37E-8E28D045E2F0}';
const myBindings = Office.context.document.bindings;
console.log("binding name" + bindingName);
myBindings.addFromNamedItemAsync(currentAddress, 'matrix', { id: bindingName },
(result) => {
console.log("binding created");
});
});
});
}

关于javascript - 对面平台无法识别 Office.js 绑定(bind)(Office Online 与 Office Desktop),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49520532/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com