如何在HTML Body中格式化数字,以便在Google Apps脚本上自动发送电子邮件

问题描述 投票:0回答:2

我正在尝试格式化我在Google Apps脚本上创建的自动电子邮件中的数字。我正在从现有的Google表格中提取数字。在Google表格中,数字格式正确(逗号,最多2个小数点)即。 123,456.78 - 但是当我为自动电子邮件调用此数据时,它会忽略Google表格中的数字格式,即。 123456.7891011

有没有办法让我的自动电子邮件中的数字遵循相同的数字格式?或者使用代码强加数字格式的方法?仅供参考,我正在使用HTML在我的电子邮件正文中加粗,斜体和制作段落。

html email google-apps-script automation html-email
2个回答
1
投票

你可以使用Number.prototype.toFixed()


1
投票

有一种使用google工作表的方法返回显示的值:

function getCellValueWithFormat() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var cell = sheet.getRange(1,1);

  Logger.log(cell.getValue());
  Logger.log(cell.getNumberFormat());
  Logger.log(cell.getDisplayValue());}

© www.soinside.com 2019 - 2024. All rights reserved.