0

I'm using this code below to update (extend) the existing Filter Ranges.

I'd like to do the same with the existing Conditional Formatting ranges. I need to extend the range.

Any tips on how to change this code to do that is appreciated.

I know I need to use updateConditionalFormat but not sure how.

function UpdateFilterView() {
  var sheetName = "Sheet1";  //  set the sheet name.
  
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var dataSheet = ss.getSheetByName(sheetName);
  var lastRow = dataSheet.getLastRow();
  var lastColumn = dataSheet.getLastColumn();
  var sheetId = dataSheet.getSheetId();
  var spreadsheetId = ss.getId();
  var filterViews = Sheets.Spreadsheets.get(spreadsheetId, {ranges: [sheetName], fields: "sheets(filterViews)"}).sheets[0].filterViews;
  var requests = filterViews.map(e => ({
    updateFilterView: {
      filter: {
        filterViewId: e.filterViewId,
        range: {sheetId: sheetId, startRowIndex: 0, endRowIndex: lastRow, startColumnIndex: 0, endColumnIndex: lastColumn}
      },
      fields: "*",
    }
  }));
  Sheets.Spreadsheets.batchUpdate({requests: requests}, spreadsheetId);
}
Tony
  • 1
  • First, from your showing script, if you had used my sample script at https://stackoverflow.com/a/64348807/7108653 , I deeply apologize that my answer was not useful for your situation. About your question, I have to apologize for my poor English skill. Unfortunately, I cannot understand `I'd like to do the same with the existing Conditional Formatting ranges. I need to extend the range.`. In order to correctly understand your question, can you provide the sample input and output situations you expect as the image? By this, I would like to try to understand it. – Tanaike Feb 05 '22 at 00:00
  • @Tanaike thank you for replying. I want to update Conditional Formatting ranges, see https://developers.google.com/sheets/api/guides/conditional-format?hl=en – Tony Feb 07 '22 at 16:41
  • Thank you for replying. I have to apologize for my poor English skill again. From `I want to update Conditional Formatting ranges, see developers.google.com/sheets/api/guides/…`, unfortunately, I cannot still understand your question. But I would like to try to understand it. When I could correctly understand it, I would like to think of the solution. I would be grateful if you can forgive my poor English skill. – Tanaike Feb 08 '22 at 00:10
  • @Tanaike what language do you speak? – Tony Feb 08 '22 at 01:40
  • Thank you for replying. I'm using the Japanese language. – Tanaike Feb 08 '22 at 01:50
  • @Tanaike 範囲の最後の行を拡張します。 – Tony Feb 08 '22 at 02:06
  • @Tanaike 範囲を大きくする – Tony Feb 08 '22 at 02:08
  • Thank you for replying. I can understand `範囲の最後の行を拡張します。` and `範囲を大きくする` as the Japanese language. But unfortunately, I cannot imagine your goal. So I cannot think of a solution. This is due to my poor skill. I deeply apologize for this. But I would like to try to understand it. When I could correctly understand it, I would like to think of the solution. I would be grateful if you can forgive my poor skill. – Tanaike Feb 08 '22 at 02:10

0 Answers0