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

213
Visualizações
How do I set a number format in Google Sheets?

I'm trying to set a number format for a message in an email (this script is an email sender that takes data from a cell and puts it into a message). I don't really know how to code, but I've managed to put this together and get it to work well, so that's why my mistake might seem incredibly obvious.

Here's the working script without my attempt at number formatting:

function sendEmails() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName('Emails'); // change Sheet1 to the name of your sheet
  const data = sh.getRange(2, 1, sh.getLastRow() - 1, 5).getValues();
  data.forEach((r, i) => {
    let sendemailValue = r[1];
    if (sendemailValue === 'X') {
      let lrow = sh.getLastRow();
      let name = r[0];
      let amount = r[2];
      let item = r[3];
      let emailAddress = r[4]; //this is column 5
      let message =
        'Hello ' + name + ', your receipt is ' + amount + ' for your ' + item;
      let subject = 'Your Receipt.';
      if (emailAddress) {
        MailApp.sendEmail(emailAddress, subject, message);
      } else {
        console.log(`Row: ${i + 2}`); //will let you know what row it's failing on
      }
    }
  });
}

And here is my attempt which failed:

function sendEmails() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName('Emails'); // change Sheet1 to the name of your sheet
  const data = sh.getRange(2, 1, sh.getLastRow() - 1, 5).getValues();
  data.forEach((r, i) => {
    let sendemailValue = r[1];
    if (sendemailValue === 'X') {
      let lrow = sh.getLastRow();
      let name = r[0];
      let amount = r[2];
      amount.setNumberFormat('$#,##0.00;$(#,##0.00)');
      let item = r[3];
      let emailAddress = r[4]; //this is column 5
      let message =
        'Hello ' + name + ', your receipt is $' + amount + ' for your ' + item;
      let subject = 'Your Receipt.';
      if (emailAddress) {
        MailApp.sendEmail(emailAddress, subject, message);
      } else {
        console.log(`Row: ${i + 2}`); //will let you know what row it's failing on
      }
    }
  });
}

The change is that I added amount.setNumberFormat("$#,##0.00;$(#,##0.00)"), which doesn't work.

The error I get is:

"TypeError: amount.setNumberFormat is not a function".

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