异常:格式错误 HTML 内容:</div> 错误

Exception: Malformed HTML content: </div> Error

我试图让我的 Google 传播 sheet 发送一封电子邮件,其中包含 sheet 的数据,这也是 html 格式化的。每当我尝试 运行 时,我都会收到以下错误...

Error Exception: Malformed HTML content: . eval
eval
myFunction @ waiverClaim.gs:37

我找不到问题所在。我认为问题出在第 37 行“const htmlForEmail = htmlTemplate.evaluate().getContent();”但我不知道怎么了,希望这里有人能帮忙!

这是脚本im 运行ning

function myFunction() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const ws = ss.getSheetByName("Football");

  const h1 = ws.getRange("A1").getValue();
  const subheader = ws.getRange("A4:F4").getValues();
  const priority = subheader[0][0];
  const player = subheader[0][1];
  const transaction = subheader[0][2];
  const bid = subheader[0][3];
  const years = subheader[0][4]; 
  const dropped = subheader[0][5];

  const lr =  ws.getLastRow();

  const tableRangeValues = ws.getRange(5,1,lr-5,6).getValues();

  const totalLine = ws.getRange(lr,3,1,6).getValues();
  const totalText = totalLine[0][0];
  const totalSum = totalLine[0][1];

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

htmlTemplate.h1 = h1;
htmlTemplate.subheader = subheader;
htmlTemplate.priority = priority;
htmlTemplate.player = player;
htmlTemplate.transaction = transaction;
htmlTemplate.bid = bid;
htmlTemplate.years = years;
htmlTemplate.dropped = dropped;
htmlTemplate.totalText = totalText;
htmlTemplate.totalSum = totalSum;
htmlTemplate.tableRangeValues = tableRangeValues;


const htmlForEmail = htmlTemplate.evaluate().getContent();

console.log(htmlForEmail);

GmailApp.sendEmail(
  "me@gmail.com",
  "Waiver Claim Submission",
  "Tom Brady  1 year",
  { htmlBody: htmlForEmail }
);

}

和对应的html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
       </head>
        <body>
             <div>

                <div>
                      <h1><?= h1 ?></h1>
                </div>
                      
                <div> 
                      <div <?= subheader ?></div>
                </div>

              </div> 

        <table>
              <thead> 
                        <tr> 
                            <th><?= priority ?></th>
                            <th><?= player ?></th>
                            <th><?= transaction ?></th>
                            <th><?= bid ?></th>
                            <th><?= years ?></th>
                            <th><?= dropped ?></th>
                        </tr>  
                
               </thead>
       
               <tbody> 
                        <tr> 
                            <td>Col D1</td>
                            <td>Col D2</td>
                            <td>Col D3</td>
                            <td>Col D4</td>
                            <td>Col D5</td>
                            <td>Col D6</td>
                        </tr>  
              </tbody>


                <tfoot>
                        <tr>
                            <td></td>
                            <td></td>
                            <td><?= totalText ?></td>
                            <td><?= totalSum ?></td>
                            <td></td>
                            <td></td>     
                        </tr> 
                </tfoot>
          </table>    
     </body>
</html>

如果我需要提供有关情况的更多信息,我会很乐意。

您在 <div <?= subheader ?></div> 中错过了 >

试试这个:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
       </head>
        <body>
             <div>

                <div>
                      <h1><?= h1 ?></h1>
                </div>
                      
                <div> 
                      <div> <?= subheader ?></div>
                </div>

              </div> 

        <table>
              <thead> 
                        <tr> 
                            <th><?= priority ?></th>
                            <th><?= player ?></th>
                            <th><?= transaction ?></th>
                            <th><?= bid ?></th>
                            <th><?= years ?></th>
                            <th><?= dropped ?></th>
                        </tr>  
                
               </thead>
       
               <tbody> 
                        <tr> 
                            <td>Col D1</td>
                            <td>Col D2</td>
                            <td>Col D3</td>
                            <td>Col D4</td>
                            <td>Col D5</td>
                            <td>Col D6</td>
                        </tr>  
              </tbody>


                <tfoot>
                        <tr>
                            <td></td>
                            <td></td>
                            <td><?= totalText ?></td>
                            <td><?= totalSum ?></td>
                            <td></td>
                            <td></td>     
                        </tr> 
                </tfoot>
          </table>    
     </body>
</html>