Reputation: 2326
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..
Upvotes: 3
Views: 7199
Reputation: 2326
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.
Upvotes: 5