最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

google sheets - Problem with dynamic setting of v axis range - Stack Overflow

programmeradmin6浏览0评论

I'm trying to follow the instructions from this post: How to dynamically adjust a Google Sheets chart vertical (y) axis minimum and maximum value to data set? but I'm getting an access exception. I've added a test to verify that I can access cells on the sheet and that works but the call to updateChart(chart) fails saying:

Exception: Service Spreadsheets failed while accessing document with id <my sheet's iD>. at updateChart(Code:14:9)

The "Hello" and values for min/max do correctly appear in D46:D48. I have no known (to me) permissions set on the sheet or on any ranges within.

Any idea why I'm getting this exception?

 function updateChart(){

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('NetWorth Dashboard');
  sheet.getRange('d46').setValue("HELLO");
  var nw_max = sheet.getRange("nw_dev_chart_max").getValue();
  var nw_min = sheet.getRange("nw_dev_chart_min").getValue(); 
  sheet.getRange('d47').setValue(nw_min);
  sheet.getRange('d48').setValue(nw_max); 
  var chart = sheet.getCharts()[0];
  chart = chart.modify()
    .setOption('vAxes.0.viewWindow.max', nw_max)
    .setOption('vAxes.0.viewWindow.min', nw_min)
    .build();
  
  sheet.updateChart(chart);  
 }

I reverted the script's setOption lines and created an example spreadsheet: #gid=906716897

发布评论

评论列表(0)

  1. 暂无评论