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

271
Visualizações
How do I remove a specific custom conditional format from all ranges that use it? I am using the delete() method, but that doesn't work

When I apply the conditional formats, I store it in the conditionalFormatCols and conditionalFormatRows variables. I then use the delete() method on these variables, but this doesn't delete the conditional formatting on the cells. How do I delete conditional formatting so it no longer shows up in the workbook?

let eventResult;
let navAidIsOn = false;
let conditionalFormatCols;
let conditionalFormatRows;

async function navAid() {
  await Excel.run(async (context) => {
    if (!navAidIsOn) {
      applyConditionalFormatting();
      const sheet = context.workbook.worksheets.getActiveWorksheet();
      eventResult = sheet.onSelectionChanged.add(navAidListener);
      navAidIsOn = !navAidIsOn;
      
    } else {
      turnNavAidOff();
    }
  });
}

async function turnNavAidOff(){
  await Excel.run(eventResult.context ,async (context) => {
    eventResult.remove()

Here I try to use the delete() method

    conditionalFormatCols.delete();
    conditionalFormatRows.delete();

    await context.sync();
    
    navAidIsOn = !navAidIsOn;
  });
}

async function navAidListener() {
  applyConditionalFormatting();
}

async function applyConditionalFormatting() {
  await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getActiveWorksheet();

    let ranges;
    let rangeArray = [];
    await context.sync();

    let columns;
    let rows;
    

    ranges = context.workbook.getSelectedRanges();
    await context.sync();

    ranges.load("address");
    await context.sync();
    let rangeStrs = ranges.address.split(",");
    rangeStrs.forEach((rangeStr) => {
      rangeArray.push(sheet.getRange(rangeStr).load("columnIndex, rowIndex, rowCount, columnCount"));
    });
    await context.sync();

    rangeArray.forEach(async (range) => {
      columns = sheet.getRangeByIndexes(0, range.columnIndex, 1048576, range.columnCount);
      rows = sheet.getRangeByIndexes(range.rowIndex, 0, range.rowCount, 16384);
      await context.sync();

      conditionalFormatCols = columns.conditionalFormats.add(Excel.ConditionalFormatType.custom);
      conditionalFormatCols.custom.rule.formula = "TRUE";
      conditionalFormatCols.custom.format.fill.color = "#D2F0E0";

      conditionalFormatRows = rows.conditionalFormats.add(Excel.ConditionalFormatType.custom);
      conditionalFormatRows.custom.rule.formula = "TRUE";
      conditionalFormatRows.custom.format.fill.color = "#D2F0E0";

      await context.sync();
    });
  });
}
about 4 years ago · Juan Pablo Isaza
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