0

I was trying to use this Microsoft tutorial Excel Chart Add-in - Javascript API

In the first example, it has the code

Excel.run(function (context) {
    var sheet = context.workbook.worksheets.getItem("Sample");
    var dataRange = sheet.getRange("A1:B13");
    var chart = sheet.charts.add("Line", dataRange, "auto");

    chart.title.text = "Sales Data";
    chart.legend.position = "right"
    chart.legend.format.fill.setSolidColor("white");
    chart.dataLabels.format.font.size = 15;
    chart.dataLabels.format.font.color = "black";

    return context.sync();
}).catch(errorHandlerFunction);

If I run the code example I receive 2 errors. One that it cannot find excel from

Excel.run

And the errorhandler function is not defined, which appears to be correct.

Are these typos in new Microsoft documents? If not what have I got to change?

Version: excel 365 online build 16.0.13615.35052

sayth
  • 6,696
  • 12
  • 58
  • 100
  • 1
    Can you provide more details about what Excel Version you are using? (i.e. send the details in File->Account->About excel – Juan Balmori Dec 18 '20 at 03:59
  • @JuanBalmori Its excel 365 online build 16.0.13615.35052 – sayth Dec 19 '20 at 06:03
  • I cant find a release with such build number, is this the Excel for Windows or Universal? if you can provide a screenshot will be great. i added an answer after trying the code, in the meantime. – Juan Balmori Dec 21 '20 at 19:46

1 Answers1

0

2 things that you need to make sure you have in order to run this code succesfully.

  1. Please add the errorHandlerFunction this could be be as easy as this:

function errorHandlerFunction(e ){
  console.log("exception" + e ); 
}
  1. Make sure you have a worksheet named "Sample". Make sure its exactly that name without trailing blank spaces.
Juan Balmori
  • 4,898
  • 1
  • 8
  • 17