Summary: Some charts (when not the first chart), cause errors in Excel Online with chart.getImage().
Usage scenario: I use chart.getImage()
to get the base64 encoded image so charts can be programmatically inserted into Word/PowerPoint documents. It is used in the Excel-to-Word Document Automation Add-In.
- There is never an issue with Excel for Windows or Mac. Issue only occurs with Excel Online.
- Error only occurs with some chart types, such as Pareto, Funnel, and common charts with some customization
- Error is not consistent: cannot always predict it, same chart, same code sometimes works fine.
- Position of chart seems to matter. First chart added never seems to produce errors.
- Type of error is not consistent. Is either:
UnsupportedOperation
,GeneralException
, orValueNotLoaded
. - Method details are here: https://dev.office.com/reference/add-ins/excel/chart
Is this a bug that can be fixed? Is there a known workaround?
Simplified Code that can reproduce error (in Script Lab):
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));
}
});
}
Sample Error Returns (I've encountered 3 types from this getImage()
issue):
{
"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"
}
}