简体   繁体   English

使用Google脚本将电话号码字符串从Google表单格式化为电子表格,再转换为电子邮件草稿

[英]Format phone number string from google form to spreadsheets into an email draft using google script

For the most part of this code I have down. 在这段代码的大部分时间内,我都很失望。 The only issue I am having is formatting a phone number that has been inputted to the Google Form. 我唯一遇到的问题是格式化输入到Google表单中的电话号码。 On the Spreadsheet the values come in looking like 1234567890, just a string of numbers. 在电子表格上,值看起来像1234567890,只是一串数字。 I am using body.replaceText("%PHONE1%", row[2]); 我正在使用body.replaceText("%PHONE1%", row[2]); to replace %PHONE1% in the template document. 替换模板文档中的%PHONE1%。 Issue is it numbers come in the same as the spreadsheet 1234567890 and I want the phone number to look like (123) 456-7890. 问题是号码与电子表格1234567890相同,我希望电话号码看起来像(123)456-7890。 It may possibly something like 它可能像

Utilities.formatString('%11.6f', 123.456); Utilities.formatString('%11.6f',123.456);

Please help, im a super newb at any type of scripting any help would be appreciated. 请帮忙,在任何类型的脚本编写上都是超级新手,将不胜感激。 Thank you 谢谢

Here's a simple example: 这是一个简单的例子:

function formatPhoneNumber()
{
  var s='1234567890';
  if(s)
  {
    var mA=s.match(/(\d{3})(\d{3})(\d{4})/);
    var s=Utilities.formatString('(%s) %s-%s', mA[1],mA[2],mA[3]);
    var ui=HtmlService.createHtmlOutput(s);
    SpreadsheetApp.getUi().showModelessDialog(ui, 'Phone Number')
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用谷歌脚本在谷歌表中加载弹出草稿电子邮件 - Loading a popup draft email in google sheets using google script 如何使用谷歌应用程序脚本发送草稿电子邮件 - How to send a draft email using google apps script 谷歌应用程序脚本添加一个组以草拟电子邮件 - google apps script adding a group to draft email 使用 Google Apps 脚本将网页转换为 Google 电子表格? - Webpage into Google Spreadsheets using Google Apps Script? 正则表达式使用 Google Apps 脚本格式化字符串中的数字 - Regex to format number in string using Google Apps script 使用 GmailApp 从 Google App 脚本创建 HTML 草稿 - Create HTML Draft from Google App script using GmailApp 如何使用Google Apps脚本将Google文档文本导入电子邮件草稿 - How to Import Google doc text into Email draft using Google Apps Script 如何使用 Google Script 处理从 Forms 到电子表格的日期 - How to deal with dates from Forms to Spreadsheets using Google Script 使用 Apps 脚本将表格从电子表格附加到 Google 文档 - Appending tables to Google Docs from Spreadsheets using Apps Script 使用来自谷歌表单和不同电子表格的信息自动发送电子邮件? - Automated emailing using information from a google form and different spreadsheets?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM