如何在google工作表单元格中保持HTML标记,而不会破坏html标记

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

我正在尝试使用谷歌工作表在单元格中添加完整的电子邮件HTML,其中我有文本,图像src,href src等变量。

现在我使用谷歌脚本用值替换标签,以便我可以复制完整的HTML并将其粘贴到电子邮件营销系统中。

我这样做是因为我的电子邮件营销系统不支持变量。

但是,我注意到,当我在单元格中粘贴HTML模板标记时,Google工作表会在现有的""周围添加一组额外的""

例如,如果这是我粘贴的HTML:

<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>
<p>My first paragraph.</p>
<a href="https://www.Google.com">Visit Google</a>


</body>
</html>

这将改为:

<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>
<p>My first paragraph.</p>
<a href=""https://www.Google.com"">Visit Google</a>


</body>
</html>

注意:

<a href="https://www.Google.com">Visit Google</a>

Google表格正在我的href src周围添加额外的设置ok ""。所有标签都有同样的问题。

<a href=""https://www.Google.com"">Visit Google</a>

我担心的是,google sheet是否可以在单元格中保持html原样?任何解决这个问题的方法?

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

试试这个:

//Just enter the strings shown below into those cells in Sheet1 which no quotations and then run the script and you'll see your html
//A1=My First Heading
//A2=My first paragraph.
//A3=http://google.com
//A4=Visit Google

function displayEmailHtml() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName('Sheet1');
  var rg=sh.getRange(1,1,4,1);
  var vA=rg.getValues();
  var html=Utilities.formatString('<!DOCTYPE html><html><body><h1>%s</h1><p>%s</p><a href="%s">%s</a>/body></html>',vA[0][0],vA[1][0],vA[2][0],vA[3][0]);
  var userInterface=HtmlService.createHtmlOutput(html);
  SpreadsheetApp.getUi().showModelessDialog(userInterface, 'My Email Html');
}

要回答你的第二个问题,试试这个:

function displayEmailHtml() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName('Sheet1');
  var rg=sh.getRange(1,1,4,1);
  var vA=rg.getValues();
  var html=Utilities.formatString('<!DOCTYPE html>\n<html>\n<body>\n<h1>%s</h1>\n<p>%s</p>',vA[0][0],vA[1][0]);
  html+=Utilities.formatString('\n<a href="%s">%s</a>\n</body>\n</html>',vA[2][0],vA[3][0]);
  html=html.replace(/>/g,'&gt');
  html=html.replace(/</g,'&lt');
  html=Utilities.formatString('<pre>%s</pre>',html);
  var userInterface=HtmlService.createHtmlOutput(html);
  SpreadsheetApp.getUi().showModelessDialog(userInterface, 'My Email Html');
}
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.