Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda