This code works well in Excel online but not works in Excel desktop. In Excel Desktop it generate error in browser log : "This operation is not permitted for the current object." on the line "chart.legend.legendEntries.getItemAt(i).visible".
Here the sample of the code where the problem occurs :
// Create an chart.
chart = activeSheet.charts.add(chartType, chartRange, 'Auto');
...
// Add a serie
for (let i = 0; i < nbSeries; ++i) {
const newSeries = chart.series.add(legend);
}
...
// Set legend visibility
for (let i = 0; i < nbSeries; i += 1) {
chart.legend.legendEntries.getItemAt(i).visible = false;
}
The legendEntry is available since ExcelApi 1.7. My Excel is an version 1912.
Thank you for you help !