带有 html 的应用程序脚本

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

我使用 appscript 和 html 在 Gmail 上发送特定列。

但是我需要制作 col1 的可点击文本(所有数据)

需要帮助。我粘贴了整个代码,请检查。或者也可以将注释行放在 html 页面代码中,我想要使其可点击的列文本。

通过电子邮件发送 html 代码


<!DOCTYPE html>

<html>

  <head>

    <base target="_top">

    <style>

     

      table,

      th,

      td {

        border: 1px solid black;

        border-collapse:collapse;

      }

    </style>

  </head>

  <body>

    

    <div>

        <div>

          <table style="border:1px;">

            <thead>

              <tr style="color:purple;font-size:16px;">

                <th><?= Taskhindi ?></th>

                <th><?= Task ?></th>

                <th><?= Freq ?></th>

              </tr>

            </thead> 

            <tbody>          

                <? tableRangeValues.forEach((r,i) =>{

                  let color ;

                  if(i % 2 === 0) {color = "silver"} else {color = "light-grey"}

                ?>

                <tr style="background-color :<?= color ?>;">

                  <td align="center"> <a href=  <?= r[0] ?>> </td>  //need to make this column  all cells text clickable 

                  <td align="center"><?= r[1] ?></td>

                  <td align="center"><?= r[2] ?></td>

                </tr> <?}) ?>

            </tbody>

          </table>

        </div>

    </div>

  </body>

</html>


Email.gs 文件代码。

function tablesend ()

{

  const ss =SpreadsheetApp.getActiveSpreadsheet();

  const ws =ss.getSheetByName("UPDATE TASK");



  const Subheader = ws.getRange("B2:I2").getValues();

  const headers = ws.getRange("B3:I3").getValues();

  const Taskhindi = headers[0][0];

  const Task = headers[0][1];

  const Freq = headers[0][2];

  //var r = [];

 



  const maxRows=ws.getMaxRows();

  const lr =ws.getLastRow();



  const tableRangeValues =ws.getRange(4, 2,lr-4,3).getValues();



  const htmltemplate = HtmlService.createTemplateFromFile("email");

  htmltemplate.Subheader = Subheader;

  htmltemplate.headers = headers;

  htmltemplate.Taskhindi = Taskhindi;

  htmltemplate.Task = Task;

  htmltemplate.Freq = Freq;

 

  htmltemplate.tableRangeValues = tableRangeValues;

 // htmltemplate.r =r;



  if(maxRows-lr !=0)

  {

    ws.deleteRows(lr+1, maxRows-lr);

  }



  const htmlforemail = htmltemplate.evaluate().getContent();



  console.log(htmlforemail);





  GmailApp.sendEmail("[email protected]",

  "your report table",

  "please open this mail with a client that support html",

  { htmlBody:htmlforemail }

  );

}
javascript html google-sheets google-apps-script
1个回答
0
投票

你有这么多未定义的变量,我只是想给你一个函数的工作示例,该函数使用模板化 html 将 2d 数据传递到对话框中。也许如果你有一些可以开始工作的东西,你可以自己继续。

gs:

function myFunck1() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Sheet0");
  const vs = sh.getDataRange().getValues();
  return vs;
}

function launchTheDialog() {
  SpreadsheetApp.getUi().showModelessDialog(HtmlService.createTemplateFromFile('ah1').evaluate(),"Dialog");
}

html:

<!DOCTYPE html>
<html>
<head>
  <base target="_top">
</head>
<body>
    <div id="tabledata">
       <? var vs = myFunck1(); ?>
       <table>
         <? vs.forEach((r,i)=>{ ?>
           <tr>
           <? r.forEach((c,j)=>{ ?>
             <? if(i == 0) { ?>
            <th style="padding:2px 5px;font-weight:bold;border:1px solid black;"><?= c ?> </th>           
           <? } else { ?>
             <td style="padding:2px 5px;border:1px solid black;"><?= vs[i][j] ?> </td>
           <? } ?>
         <?  }); ?>
           </tr>
         <? }); ?>
       </table>
     </div> 
</body>
</html>
© www.soinside.com 2019 - 2024. All rights reserved.