Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在google应用程序脚本中重新构造HTML表?_Html_Css_Email_Google Apps Script_Html Table - Fatal编程技术网

如何在google应用程序脚本中重新构造HTML表?

如何在google应用程序脚本中重新构造HTML表?,html,css,email,google-apps-script,html-table,Html,Css,Email,Google Apps Script,Html Table,我有一个谷歌表格,后面有一个生成电子邮件的脚本。电子邮件的正文是一个HTML表。这一切都很好,除了表格在电子邮件中的结构。由于最后一行中链接的长度,第二列被压过,文本和返回值之间有很大的空间。是否需要修改表结构,使第2列与第1列相邻?也许有一个对齐选项或什么东西允许链接溢出?这是表格HTML 功能表1提交(e){ 如果(e.values&&e.values[1]&&e.values[2]){ var html=''; html+=Utilities.formatString(“%s%s%s'

我有一个谷歌表格,后面有一个生成电子邮件的脚本。电子邮件的正文是一个HTML表。这一切都很好,除了表格在电子邮件中的结构。由于最后一行中链接的长度,第二列被压过,文本和返回值之间有很大的空间。是否需要修改表结构,使第2列与第1列相邻?也许有一个对齐选项或什么东西允许链接溢出?这是表格HTML


功能表1提交(e){
如果(e.values&&e.values[1]&&e.values[2]){
var html='';
html+=Utilities.formatString(“%s%s%s',“”,'Safety Findings Comment:',e.values[7]);
html+=Utilities.formatString(“%s%s%s”,“”,”https://docs.google.com/spreadsheets/d/e/2PACX-1vQj3j6QgrCyvULYo1IeE3q9L9Gzvz2tVvNI8650nhl-L0cQwyx93tRIeuXPxxxxxxxxxxxxxxxxxxx/pubhtml#',' ' );
html+='';
Logger.log(html);
sendmail(getGlobal('form1Email')、getGlobal('form1Subject')、''、{htmlBody:html});
}

}
我准备回答你的问题,但这是你的密码:

function form1Submit(e) {
      if(e.values && e.values[1] && e.values[2]) {
        var html='<table>';
        html+=Utilities.formatString('<tr><td>%s</td><td><strong>%s</strong></td><td>%s</td></tr>','&nbsp;','Safety Findings Comment:',e.values[7]);
        html+=Utilities.formatString('<tr><td>%s</td><td colspan ="2">%s</td><td>%s</td></tr>','&nbsp;','https://docs.google.com/spreadsheets/d/e/2PACX-1vQj3j6QgrCyvULYo1IeE3q9L9Gzvz2tVvNI8650nhl-L0cQwyx93tRIeuXPxxxxxxxxxxxxxxxxxxx/pubhtml#','&nbsp;' );
        html+='</table>';
    Logger.log(html);
    GmailApp.sendEmail(getGlobal('form1Email'), getGlobal('form1Subject'), '', {htmlBody:html});
  }
}
函数表1提交(e){
如果(e.values&&e.values[1]&&e.values[2]){
var html='';
html+=Utilities.formatString(“%s%s%s',“”,'Safety Findings Comment:',e.values[7]);
html+=Utilities.formatString(“%s%s%s”,“”,”https://docs.google.com/spreadsheets/d/e/2PACX-1vQj3j6QgrCyvULYo1IeE3q9L9Gzvz2tVvNI8650nhl-L0cQwyx93tRIeuXPxxxxxxxxxxxxxxxxxxx/pubhtml#',' ' );
html+='';
Logger.log(html);
sendmail(getGlobal('form1Email')、getGlobal('form1Subject')、''、{htmlBody:html});
}
}
我不知道e.values是什么样子,所以我真的不知道如何测试代码,因为我有未定义的变量。所以,虽然你的例子可能是最小的,但它是不可复制的

所以我自己写了一篇文章。我还将结果显示在对话框中,因为我不想发送电子邮件。css在html字符串中。想必,你可以在电子邮件中做到这一点

function form1Submit(e) {
      if(e.values && e.values[1] && e.values[2]) {
        var url='https://docs.google.com/spreadsheets/d/e/2PACX-1vQj3j6QgrCyvULYo1IeE3q9L9Gzvz2tVvNI8650nhl-L0cQwyx93tRIeuXPxxxxxxxxxxxxxxxxxxx/pubhtml#';
        var html='<style>td,th{padding:2px;border:1px solid black;overflow-wrap: break-word;}table{table-layout:fixed;width:100%;}</style><table>';
        html+=Utilities.formatString('<tr><td>&nbsp;</td><td><strong>Safety Findings</strong></td><td>%s</td></tr>',e.values[7]);
        html+=Utilities.formatString('<tr><td>&nbsp;</td><td>%s</td><td>&nbsp;</td></tr>',url);
        html+='</table>';
    Logger.log(html);
    //GmailApp.sendEmail('email', 'Subjecet', '', {htmlBody:html});
    SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html), "Test");    

  }
}

function testAbove() {
  var e={values:['one','two','three','four','five','six','seven','eight','nine']};
  form1Submit(e) 
}
函数表1提交(e){
如果(e.values&&e.values[1]&&e.values[2]){
var url='1〕https://docs.google.com/spreadsheets/d/e/2PACX-1vQj3j6QgrCyvULYo1IeE3q9L9Gzvz2tVvNI8650nhl-L0cQwyx93tRIeuXPxxxxxxxxxxxxxxxxxxx/pubhtml#';
var html='td,th{padding:2px;border:1px纯黑色;溢出换行:break word;}表{表布局:fixed;宽度:100%;}';
html+=Utilities.formatString(“安全发现”%s',e.values[7]);
html+=实用程序.formatString(“%s”,url);
html+='';
Logger.log(html);
//sendmail('email','subjectet','',{htmlBody:html});
SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html),“测试”);
}
}
函数testAbove(){
var e={值:['1','2','3','4','5','6','7','8','9']};
表格1提交(e)
}
下面是该对话框的外观:

您也可以这样做:

function form1Submit(e) {
      if(e.values && e.values[1] && e.values[2]) {
        var url='https://docs.google.com/spreadsheets/d/e/2PACX-1vQj3j6QgrCyvULYo1IeE3q9L9Gzvz2tVvNI8650nhl-L0cQwyx93tRIeuXPxxxxxxxxxxxxxxxxxxx/pubhtml#';
        var html='<style>td,th{padding:2px;border:1px solid black;overflow-wrap: break-word;}table{table-layout:fixed;width:100%;}</style><table>';
        html+=Utilities.formatString('<tr><td style="width:10%;">&nbsp;</td><td style="width:60%;"><strong>Safety Findings</strong></td><td style="width:30%;">%s</td></tr>',e.values[7]);
        html+=Utilities.formatString('<tr><td>&nbsp;</td><td>%s</td><td>&nbsp;</td></tr>',url);
        html+='</table>';
    Logger.log(html);
    //GmailApp.sendEmail('email', 'Subjecet', '', {htmlBody:html});
    SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html), "Test");    

  }
}
函数表1提交(e){
如果(e.values&&e.values[1]&&e.values[2]){
var url='1〕https://docs.google.com/spreadsheets/d/e/2PACX-1vQj3j6QgrCyvULYo1IeE3q9L9Gzvz2tVvNI8650nhl-L0cQwyx93tRIeuXPxxxxxxxxxxxxxxxxxxx/pubhtml#';
var html='td,th{padding:2px;border:1px纯黑色;溢出换行:break word;}表{表布局:fixed;宽度:100%;}';
html+=Utilities.formatString(“安全发现”%s',e.values[7]);
html+=实用程序.formatString(“%s”,url);
html+='';
Logger.log(html);
//sendmail('email','subjectet','',{htmlBody:html});
SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html),“测试”);
}
}


您可以通过单独调整每列的宽度来进行调整。

欢迎来到StackOverFlow。请借此机会学习并学习如何,以及。删除未定义的变量和/或为我们提供一个Cooper,您帮助我开始编写,但我添加了链接,它抛出了对齐。这里是原来的帖子,但是表单和表单不再是最新的。这是新的表格和表格。这两个都是示例,您可以随意提交回复和编辑。我已经在工作表中添加了问题的图像和期望的结果。库珀,谢谢你坚持我,并为我提供了一个有效的解决方案!我把更新后的脚本放在我的原始问题中。希望我能正确地更新所有内容。再次感谢你@Cooper!