Office.js Excel Online> chart.getImage()错误

时间:2018-03-29 18:49:51

标签: javascript excel office-js

摘要:某些图表(当不是第一个图表时)会导致Excel Online中的错误与chart.getImage()。

使用方案:我使用chart.getImage()获取base64编码图像,以便可以通过编程方式将图表插入到Word / PowerPoint文档中。它用于Excel到Word文档自动化加载项。

  • Excel for Windows或Mac从未出现过问题。仅限问题 与Excel Online一起发生。
  • 仅在某些图表类型中出现错误, 例如Pareto,Funnel和带有一些自定义的常见图表
  • 错误不一致:不能总是预测它,相同的图表,相同 代码有时工作正常。
  • 图表的位置似乎很重要。第一 图表添加似乎永远不会产生错误。
  • 错误类型不一致。是:UnsupportedOperationGeneralExceptionValueNotLoaded
  • 方法详情如下: https://dev.office.com/reference/add-ins/excel/chart

这是一个可以修复的错误吗?有没有已知的解决方法?

可以重现错误的简化代码(在脚本实验室中):

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"
  }
}

1 个答案:

答案 0 :(得分:1)

这可能是一个错误,团队正在努力修复它。将在修复程序可用时更新此答案。 谢谢! 涓。