2

I'm seeking pointers (sample code is appreciated) to get started on setting the height and width of every chart in a Google Sheets file.

I have to import these charts into a presentation and would prefer that they are of a specified width x height rather than approximately by dragging and sizing the window one by one..

player0
  • 124,011
  • 12
  • 67
  • 124
Vishal
  • 2,097
  • 6
  • 27
  • 45
  • In order to set the size of chart, you can use the method of `setDimensions(width, height)`. In this case, is this thread useful? https://stackoverflow.com/q/52919710 – Tanaike Feb 10 '20 at 02:00

1 Answers1

4
function resizeCharts() {
  var width = 1200;
  var height = 750;
  var target = SpreadsheetApp.getActiveSpreadsheet();
  var sheets = target.getSheets();
  for (var n = 0; n < sheets.length; n++) {
    sheet = sheets[n];
    var charts = sheet.getCharts();
    for (var i = 0; i < charts.length; i++) {
      var chart = charts[i];
      chart = chart.modify()
      .setOption('width', width)
      .setOption('height', height)
      .build();
      sheet.updateChart(chart);
    }
  }
}

This seems to do what I wanted. Can use it to perform actions on all sheets or charts as well.

Vishal
  • 2,097
  • 6
  • 27
  • 45