摘要:某些图表(当不是第一个图表时)会导致Excel Online中的错误与chart.getImage()。
使用方案:我使用chart.getImage()
获取base64编码图像,以便可以通过编程方式将图表插入到Word / PowerPoint文档中。它用于Excel到Word文档自动化加载项。
UnsupportedOperation
,GeneralException
或ValueNotLoaded
。 这是一个可以修复的错误吗?有没有已知的解决方法?
可以重现错误的简化代码(在脚本实验室中):
function run() {
Excel.run(function(ctx) {
var chart = ctx.workbook.worksheets
.getItem("Sheet1")
.charts.getItem("Chart3");
var image = chart.getImage();
return ctx.sync().then(function() {
var data = image.value;
console.log("Success: " + data.substr(0, 100));
});
}).catch(function(error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});
}
示例错误返回(我遇到了getImage()
问题中的3种类型):
{
"code": "UnsupportedOperation",
"message": "This operation is not implemented.",
"errorLocation": "Chart.getImage",
"statement": "item.getImage(undefined, undefined, undefined);",
"surroundingStatements": [
"var workbook=context.workbook;",
"var worksheets=workbook.worksheets;",
"var worksheet=worksheets.getItem(\"Sheet1\");",
"var charts=worksheet.charts;",
"var item=charts.getItem(\"rpt_Chart3\");",
"// >>>>>",
"item.getImage(undefined, undefined, undefined);",
"// <<<<<"
]
}
{
"name": "OfficeExtension.Error",
"code": "GeneralException",
"message": "An internal error has occurred.",
"traceMessages": [],
"innerError": null,
"debugInfo": {
"code": "GeneralException",
"message": "An internal error has occurred."
}
}
{
"name": "OfficeExtension.Error",
"code": "ValueNotLoaded",
"message":
"The value of the result object has not been loaded yet. Before reading the value property, call \"context.sync()\" on the associated request context.",
"traceMessages": [],
"innerError": null,
"debugInfo": {
"code": "ValueNotLoaded",
"message":
"The value of the result object has not been loaded yet. Before reading the value property, call \"context.sync()\" on the associated request context.",
"errorLocation": "clientResult.value"
}
}
答案 0 :(得分:1)
这可能是一个错误,团队正在努力修复它。将在修复程序可用时更新此答案。 谢谢! 涓。