当该组被折叠/隐藏时,chart.getImage()
方法会在组(数据>大纲>组)中导致以下错误。
我使用chart.getImage()
来获取base64编码的图像,因此可以通过编程方式将图表插入到Word / PowerPoint文档中。
此功能是Excel-to-Word文档自动化加载项的一部分。即使在组中折叠,用户也希望能够获取图像。
Excel for Windows和Excel Online(可能还有Mac)出现错误
这可能与Office.js Excel Online > chart.getImage() errors
有关这是一个可以修复的错误(或者它是否会被支持)?有没有已知的解决方法?
重现ScriptLab中的错误:
function run() {
Excel.run(function (ctx) {
var chart = ctx.workbook
.worksheets.getItem("Sheet1")
.charts.getItem("Chart1");
var image = chart.getImage();
return ctx.sync().then(function () {
console.log("done");
});
}).catch(function (error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});
}
错误详情:
{
"name": "OfficeExtension.Error",
"code": "GeneralException",
"message": "There was an internal error while processing the request.",
"traceMessages": [],
"innerError": null,
"debugInfo": {
"code": "GeneralException",
"message": "There was an internal error while processing the request.",
"errorLocation": "Chart.getImage",
"statement": "chart.getImage(undefined, undefined, undefined);",
"surroundingStatements": [
"var workbook=context.workbook;",
"var worksheets=workbook.worksheets;",
"var worksheet=worksheets.getItem(\"{54698F7A-3FA1-4058-AD3B-96EF1019AE15}\");",
"var charts=worksheet.charts;",
"var chart=charts.getItem(\"{015E9BD6-3F08-4E97-B18F-CCC65EEC17DB}\");",
"// >>>>>", "chart.getImage(undefined, undefined, undefined);",
"// <<<<<", "var chart1=charts.getItem(\"{6D2803F9-8B28-49CE-9C30-3DA6942867BD}\");",
"chart1.getImage(undefined, undefined, undefined);",
"var chart2=charts.getItem(\"{718E8A3F-00AF-4850-B63F-327C473391C2}\");",
"chart2.getImage(undefined, undefined, undefined);",
"var chart3=charts.getItem(\"{2169D771-1AE2-4BE9-8780-8B46C06CEBA9}\");"
]
},
"stack": "..."
}
堆栈追踪:
"GeneralException: There was an internal error while processing the request.
at Anonymous function (https://appsforoffice.microsoft.com/lib/1/hosted/excel-win32-16.01.js:21:219258)
at ai (https://appsforoffice.microsoft.com/lib/1/hosted/excel-win32-16.01.js:21:264887)
at ft (https://appsforoffice.microsoft.com/lib/1/hosted/excel-win32-16.01.js:21:264974)
at d (https://appsforoffice.microsoft.com/lib/1/hosted/excel-win32-16.01.js:21:264794)
at c (https://appsforoffice.microsoft.com/lib/1/hosted/excel-win32-16.01.js:21:263490)"