Ecrire un mot avec un arrière plan de couleur dans une feuille

Bonjour,

Je souhaiterais écrire "Grand Livre" dans la cellule A1 et avec un arrière plan rouge. Voici le code:

function monGrandLivre() {
  var journal = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('journal')
  var data = journal.getDataRange().getDisplayValues().filter(r => (!isNaN(Date.parse(r[0]))))
  data = data.sort(function (a, b) {
    return "" + a[1].localeCompare(b[1]);
  });
  var result = []
  result.push(['','','','Débit','Crédit'])
  data.forEach(function(donnees,ligne){
    result.push([donnees[0],donnees[1],'',donnees[3],donnees[4]])
    if (ligne != (data.length -1)){
      if (data[ligne+1][1] != data[ligne][1]){
        result.push(['','','','',''])
        result.push(['','','','',''])
      }
    }
  })
  var grandLivre = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('grand livre')
  const header = grandLivre.getRange("A1");
  header.setBackground("red")
  .setValue("Grand Livre");
  grandLivre.clearContents()
  grandLivre.getRange(1,1,result.length,result[0].length).setValues(result)
  grandLivre.getRange(result.length+1,3).setValue('à reporter')
  grandLivre.getRange(result.length+1,4).setFormula('=sum(D2:D'+result.length+')')
  grandLivre.getRange(result.length+1,5).setFormula('=sum(E2:E'+result.length+')')

}
capture

Lien du fichier:
https://docs.google.com/spreadsheets/d/1kL1ujcchsRQB9253azwnOQuxxkCvoAHXn4WNblIC6gU/edit?usp=sharing

Merci de votre aide.

je n'ai pas regardé en détail ton code, mais tu peux le terminer par

grandLivre.getRange('A1').setValue('Grand Livre')
grandLivre.getRange('A1').setBackground("red")

ce qui n'entravera pas

grandLivre.getRange(1,1,result.length,result[0].length).setValues(result)

si tu mets ces 2 ligne après

Encore une fois, ça fonctionne parfaitement.

Voici le code en détail.

function monGrandLivre() {
  var journal = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('journal')
  var data = journal.getDataRange().getDisplayValues().filter(r => (!isNaN(Date.parse(r[0]))))
  data = data.sort(function (a, b) {
    return "" + a[1].localeCompare(b[1]);
  });
  var result = []
  result.push(['','','','Débit','Crédit'])
  data.forEach(function(donnees,ligne){
    result.push([donnees[0],donnees[1],'',donnees[3],donnees[4]])
    if (ligne != (data.length -1)){
      if (data[ligne+1][1] != data[ligne][1]){
        result.push(['','','','',''])
        result.push(['','','','',''])
      }
    }
  })
  var grandLivre = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('grand livre')
  grandLivre.clearContents()
  grandLivre.getRange(1,1,result.length,result[0].length).setValues(result)
  grandLivre.getRange('A1').setValue("Grand Livre")
  grandLivre.getRange('A1').setBackground("red")
  grandLivre.getRange(result.length+1,3).setValue('à reporter')
  grandLivre.getRange(result.length+1,4).setFormula('=sum(D2:D'+result.length+')')
  grandLivre.getRange(result.length+1,5).setFormula('=sum(E2:E'+result.length+')')

}

Merci énormément.

Rechercher des sujets similaires à "ecrire mot arriere plan couleur feuille"