簡體   English   中英

例外:格式錯誤的 HTML 內容:

[英]Exception: Malformed HTML content: </div> Error

我試圖讓我的谷歌電子表格發送一個 email 表格中的數據也是 html 格式。 每當我嘗試運行它時,我都會不斷收到以下錯誤...

錯誤異常:格式錯誤的 HTML 內容:. 評估
評估
我的函數@waiverClaim.gs:37

我找不到問題。 我認為問題出在第 37 行“const htmlForEmail = htmlTemplate.evaluate().getContent();” 但我不知道出了什么問題,希望這里有人可以提供幫助!

這是我正在運行的腳本

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 $45 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 <?= 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM