Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

147
Visualizações
Is it possible to remove a conditional formatting rule created via ConditionalFormatRuleBuilder

I am making custom conditional formatting rules using this method: ConditionalFormatRuleBuilder.

However, If I ever update it, say the color in .setBackground("#FF0000"), and run it again, it creates a new conditional formatting rule that conflicts with the original one.

What I want to know, is in that example is there a way to remove the rule defined as rule? For example is there an opposite of rules.push(rule);? Something like rules.remove(rule); ?

Here's an example from my code. I currently have this:

var rule1 = SpreadsheetApp.newConditionalFormatRule()
        .whenTextEqualTo(s1)
        .setBackground(s1c)
        .setRanges([r])
        .build();

var rules = curSheet.getConditionalFormatRules();
      rules.push(rule1);

curSheet.setConditionalFormatRules(rules);

Would it be possible to remove the rule defined as rule1?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you highlight your entire sheet and select Conditional Formatting from the menu, you will see a list of all of the active format rules on the right of the screen.

The order that the rules in that pane is the same order of the rules in the .getConditionalFormatRules() array.

So you can use splice() to remove which ever rule(s) you want

function deleteFormat(){
  var ss = SpreadsheetApp.getActive();
  var sheet = ss.getSheetByName("Sheet1");
  var rules = sheet.getConditionalFormatRules();
  
  // if you want to remove rules starting at the 4th rule and delete only 1 rule. 
  rules.splice(3,1);
  sheet.setConditionalFormatRules(rules);
}

I tested it on a sample sheet, and it worked. If you have any issues, add a comment and I will look into it.

Also, if you want to edit a rule programmatically, you can use slice with the builder.

  1. Build your rules as normal
  2. Get the list of rules
  3. Use slice('position to remove', 1, newRule)
  4. Set the rules

This will remove the old rule at that position in the array, and replace it with the new one.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda