简体   繁体   中英

Deleting a Chart with Invalid Coordinates or Range in a Google Spreadsheet

I've got a chart that's automatically generated inside of a spreadsheet, and it is programmatically deleted each time an update is done, with a new chart put in its place. The problem is, should the data that it's referencing be deleted first, I get the error: "The coordinates or dimensions of the range are invalid."

This error points to the first line of the deleting charts function:

var charts = convertSheet.getCharts();
  for (var i in charts) {
    convertSheet.removeChart(charts[i]);
  }

So apparently, if a chart has an error, Google Apps Script is unable to even access it, even if it's only to remove it. I'm not seeing a viable solution to this problem up until now. I even tried inserting new data in the range that the chart points to before attempting to delete it, so it'd have good data, but no dice. And unfortunately, it stops the entire script, how do I deal with this?

I'm still hoping someone has a better answer, but for now, I've got a somewhat working system:

  try {
    var charts = convertSheet.getCharts();
    for (var i in charts) {
      convertSheet.removeChart(charts[i]);
    }
  }
  catch(err) {
    //Ignore dat error, bro!
  }

Basically, rather than it stopping the entire script just because it couldn't delete the graph, it just leaves the broken graph there and continues with the script. It's not ideal, but the error was an extremely rare use case, so a cludgy fix is acceptable.

The problem with this solution is that it leaves a big ugly broken graph on the page, and all future attempts to clear all graphs fail, since the broken graph is still there, until someone manually deletes the graph.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM