logo
down
shadow

Google Script to Clear multiple ranges.


Google Script to Clear multiple ranges.

By : udi
Date : November 21 2020, 04:03 PM
To fix the issue you can do Unfortunately there is not currently a Apps Script method to clear multiple ranges with a single function call.
What you might find a little easier to manage is to instead define one or more data structures (even a simple array) containing the Ranges in question. Then you can clear them all by simply looping over the data structure and calling clearContent() on each Range. This would separate the work of keeping track of your Ranges from the work of clearing them. The data structure might also be useful in other areas of your code.
code :


Share : facebook icon twitter icon
Cannot get ranges from multiple sheets in google apps script

Cannot get ranges from multiple sheets in google apps script


By : sudobash
Date : March 29 2020, 07:55 AM
this will help Redian resolved it. There were no errors, the problem was in other code section.
Script to clear multiple specific ranges - Cannot call method getSheetByName of Null

Script to clear multiple specific ranges - Cannot call method getSheetByName of Null


By : Thiago Leite
Date : March 29 2020, 07:55 AM
I hope this helps . Example I'm trying to follow , Try this:
code :
function resetColumns() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheetByName('Tools')

  sh.getRange("A1:A9").clearContent();
};
Google Script -- Insert sheet with multiple ranges

Google Script -- Insert sheet with multiple ranges


By : Mobodol
Date : March 29 2020, 07:55 AM
may help you . I have a google spreadsheet (link below) that covers a single month, then I'm inserting a sheet for the next month with only a few of the ranges as carry over data. , Try this. You have to reference the inserted shee to set its values:
code :
function TDCopyV3() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = ss.getSheetByName("May 2014");
  var sheetName = ss.getName();
  var namestat = s.getRange("C3:U4").getValues();
  var carryover = s.getRange("C17:U18").getValues();
  var date = s.getRange("B13").getValue();
  var templateSheet = ss.getSheetByName('Template1');
  ss.insertSheet(sheetName +1, 0, {template: templateSheet})
  var shnew =ss.getSheetByName("Copy of HoursDemo1")
  var shnewVal=  shnew.getRange(3,3,namestat.length,namestat[0].length).getValues()
  shnew.getRange(3,3,namestat.length,namestat[0].length).setValues(namestat)
  shnew.getRange(17,3,carryover.length,19).setValues(carryover);
}
How to create a chart with multiple ranges in google apps script for google spreadsheets

How to create a chart with multiple ranges in google apps script for google spreadsheets


By : Skip
Date : March 29 2020, 07:55 AM
this one helps. I've figured out what the problems were, mostly through experimentation, I still am of the opinion the documentation is lacking clarity and good examples. But here is my my understanding.
First of, there are three classes to deal with for this problem, Sheet, EmbeddedChart and EmbeddedChartBuilder.
code :
function createCharts(){
  var sheet = getSheet('Graphs');
  var chart = sheet.newChart().setChartType(Charts.ChartType.LINE).setPosition(2,1,0,0).build(); // build returns an EmbeddedChart object 
  Logger.log(chart);
  sheet.insertChart(chart);
  chart = chart.modify().addRange(getSheet('someSheetName').getRange('B1:B999')).build();
  Logger.log(chart);
  sheet.updateChart(chart);
}
function createChart(range, x, y, title, width, height){
  // range: string; x: int; y: int; title: string; width: int; height; int
  // Creates a chart with data from all usernames for a given range at x row, y column, with a title, a width and height
  var sheet = getSheet('Graphs');
  // chart setup
  var chart = sheet.newChart()
  .setChartType(Charts.ChartType.LINE)
  .setPosition(x,y,0,0)
  .setNumHeaders(1)
  .setOption('title', title)
  .setOption('width', width)
  .setOption('height', height)
  .build();
  sheet.insertChart(chart);
  // for every username, add corresponding data into chart
  for(var i = 0; i < fortniteUsernames.length; i++){
    var username = fortniteUsernames[i];
    chart = chart.modify().addRange(getSheet(username).getRange(range)).build();
    sheet.updateChart(chart);    
  }
}
Define multiple ranges in Google Apps Script

Define multiple ranges in Google Apps Script


By : Hoang Si Nguyen
Date : March 29 2020, 07:55 AM
it should still fix some issue Performing the same operation on possibly-disjoint Ranges is most easily done with the Rangelist class, and does not require directly accessing the member Ranges. However, even if the operations are different (or conditional), a RangeList can be used to optimize the use of the Spreadsheet Service, rather than repeatedly calling Sheet#getRange.
From your code, we can determine that the goal is to operate on a set of ranges related to "true" checkboxes:
code :
var checkRange = [];
for (var i = 0; i < checkboxes.length; i++) {
  if (checkboxes[i]) {
    checkRange.push('C' + (i+9));
    Logger.log(checkRange);
  }
}
var dataRange = sheet.getRange(checkRange);
var values = dataRange.getValues();
for (var i = 0; i < values.length; i++) {
  for (var j = 0; j < values[i].length; j++) {
    if (values[i][j] == false) {
      values[i][j] = true; 
    }
  }
}
dataRange.setValues(values);
const rl = sheet.getRangeList(checkRange);
rl.getRanges().forEach(function (rg) {
  // Assumption: only single-cell ranges, based on the above checkRange code
  if (rg.getValue() == false) // matches false, null, undefined, 0, or ""
    rg.setValue(true);
});
shadow
Privacy Policy - Terms - Contact Us © festivalmusicasacra.org