我已经尝试了很多方法来实现这一点,但是我不能仅仅使用我尝试过的代码来获得PowerPoint.SlideCollection或PowerPoint.Slide。文档中没有关于这一点的示例。我可以在PowerPoint.run()中编写哪些代码片段来获取幻灯片(PowerPoint.SlideCollection)或特定的幻灯片PowerPoint.Slide?
下面是我写的代码:
function log(str) { document.getElementById('log').textContent += '\n[LOG]' + str; }
function logObject(obj) { log(JSON.stringify(obj)); }
Office.onReady(info => {
if(info.host === Office.HostType.PowerPoint) {
OfficeExtension.config.extendedErrorLogging = true;
document.getElementById("sideload-msg").style.display = "none";
document.getElementById("app-body").style.display = "flex";
document.getElementById("run").onclick = getSlideCollection;
}
});
async function getSlideCollection() {
await PowerPoint.run(async function(context) {
let slides = context.presentation.slides;
await context.sync().then((res)=>{
logObject(res);
}).catch((err)=>{
logObject(err);
});
});
}
我得到的错误是:
{"name":"RichApi.Error","code":"GeneralException","traceMessages":[],"innerError":null,"debugInfo":{"code":"GeneralException","message":"GeneralException","errorLocation":"Presentation.slides","statement":"var slides = root.slides;","surroundingStatements":["var root = context.root;","// >>>>>","var slides = root.slides;","// <<<<<"],"fullStatements":["var root = context.root;","var slides = root.slides;"]},"httpStatusCode":500}
发布于 2021-01-08 16:47:02
下面是一个简单的代码片段,可以帮助您:
function GetSlideCollection() {
await PowerPoint.run(async function(context) {
let slides = context.presentation.slides;
await context.sync();
});
}
发布于 2021-01-14 03:33:57
由于.slides
是一个beta feature (在预览中),您应该导入预览API js文件(You can refer this document)。
https://stackoverflow.com/questions/65624469
复制相似问题