Переберите все ваши листы
function loopThroughAllSheets() {
var ss=SpreadsheetApp.getActive();
var shts=ss.getSheets();
//var html='<h1>All My Sheets</h1>';
for(var i=0;i<shts.length;i++) {
//html+=Utilities.formatString('Sheet Name: <strong>%s</strong><br />',shts[i].getName());
doItOverAndOver(shts[i],ss);
}
//html+='<br /><input type="button" value="Close" onClick="google.script.host.close();" />';
//var userInterface=HtmlService.createHtmlOutput(html);
//SpreadsheetApp.getUi().showModelessDialog(userInterface, 'Sheets');
}
Чтобы ответить на ваш дополнительный вопрос, что вы делаете с этим? Что ж, если вы довольны текущим сценарием, возможно, вы сможете превратить его в функцию, как показано ниже, и вызвать ее, как показано выше;
function doitOverAndOver(sht,ss) {
var spreadsheet = ss;
spreadsheet.getRange('G1').activate();//I think you need a sheet specifier in here
var sheet = sht;
var chart = sheet.newChart()
.asLineChart()
.addRange(spreadsheet.getRange('F1:I97'))
.setMergeStrategy(Charts.ChartMergeStrategy.MERGE_COLUMNS)
.setTransposeRowsAndColumns(false)
.setNumHeaders(1)
.setHiddenDimensionStrategy(Charts.ChartHiddenDimensionStrategy.IGNORE_BOTH)
.setOption('useFirstColumnAsDomain', false)
.setOption('isStacked', 'false')
.setOption('title', 'Website Purchases, Website Purchases [1 Day After Clicking], Website Purchases [7 Days After Clicking] and Website Purchases [28 Days After Clicking]')
.setPosition(7, 2, 350, 18)
.build();
sheet.insertChart(chart);
var charts = sheet.getCharts();
chart = charts[charts.length - 1];
sheet.removeChart(chart);
chart = sheet.newChart()
.asScatterChart()
.addRange(spreadsheet.getRange('F1:I97'))
.setMergeStrategy(Charts.ChartMergeStrategy.MERGE_COLUMNS)
.setTransposeRowsAndColumns(false)
.setNumHeaders(1)
.setHiddenDimensionStrategy(Charts.ChartHiddenDimensionStrategy.IGNORE_BOTH)
.setOption('useFirstColumnAsDomain', false)
.setOption('isStacked', 'false')
.setOption('title', 'Website Purchases, Website Purchases [1 Day After Clicking], Website Purchases [7 Days After Clicking] and Website Purchases [28 Days After Clicking]')
.setPosition(7, 2, 350, 18)
.build();
sheet.insertChart(chart);
var currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
charts = sheet.getCharts();
chart = charts[charts.length - 1];
sheet.removeChart(chart);
chart = sheet.newChart()
.asScatterChart()
.addRange(spreadsheet.getRange('G1:G100000'))
.setMergeStrategy(Charts.ChartMergeStrategy.MERGE_COLUMNS)
.setTransposeRowsAndColumns(false)
.setNumHeaders(1)
.setHiddenDimensionStrategy(Charts.ChartHiddenDimensionStrategy.IGNORE_BOTH)
.setOption('useFirstColumnAsDomain', false)
.setOption('isStacked', 'false')
.setOption('title', 'Website Purchases, Website Purchases [1 Day After Clicking], Website Purchases [7 Days After Clicking] and Website Purchases [28 Days After Clicking]')
.setPosition(7, 2, 350, 18)
.build();
sheet.insertChart(chart);
charts = sheet.getCharts();
chart = charts[charts.length - 1];
sheet.removeChart(chart);
chart = sheet.newChart()
.asScatterChart()
.addRange(spreadsheet.getRange('I1:I10000'))
.addRange(spreadsheet.getRange('G1:G10000'))
.setMergeStrategy(Charts.ChartMergeStrategy.MERGE_COLUMNS)
.setTransposeRowsAndColumns(false)
.setNumHeaders(1)
.setHiddenDimensionStrategy(Charts.ChartHiddenDimensionStrategy.IGNORE_BOTH)
.setOption('useFirstColumnAsDomain', true)
.setOption('isStacked', 'false')
.setOption('title', 'Website Purchases, Website Purchases [1 Day After Clicking], Website Purchases [7 Days After Clicking] and Website Purchases [28 Days After Clicking]')
.setPosition(7, 2, 350, 18)
.build();
sheet.insertChart(chart);
charts = sheet.getCharts();
chart = charts[charts.length - 1];
sheet.removeChart(chart);
chart = sheet.newChart()
.asScatterChart()
.addRange(spreadsheet.getRange('I1:I10000'))
.addRange(spreadsheet.getRange('G1:G10000'))
.setMergeStrategy(Charts.ChartMergeStrategy.MERGE_COLUMNS)
.setTransposeRowsAndColumns(false)
.setNumHeaders(1)
.setHiddenDimensionStrategy(Charts.ChartHiddenDimensionStrategy.IGNORE_BOTH)
.setOption('useFirstColumnAsDomain', true)
.setOption('isStacked', 'false')
.setOption('title', 'Website Purchases, Website Purchases [1 Day After Clicking], Website Purchases [7 Days After Clicking] and Website Purchases [28 Days After Clicking]')
.setPosition(7, 2, 350, 18)
.build();
sheet.insertChart(chart);
spreadsheet.getRange('H978').activate();
spreadsheet.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.UP).activate();
};
Лично я бы хотел очистить вашу функцию, но это другой вопрос.