function showDialog(myHtmlCode) {
var html = HtmlService.createHtmlOutputFromFile('index.html')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(800)
.setHeight(600)
.append(myHtmlCode); // By default it embeds the code to the end of the index.html
SpreadsheetApp.getUi().showModalDialog(html, '...');
}
例如,我如何将 span 插入index.html中的 div ?
答案 0 :(得分:1)
<header class="mdl-layout__header">
<div class="mdl-layout__header-row">
<?=myContent ?>
</div>
</header>
function showDialog(myHtmlCode) {
var template = HtmlService.createTemplateFromFile('index.html') // HTML Service: Templated HTML
template.myContent = myHtmlCode; // Put our html to the prepared place in our html file.
var modifiedHtml = template.evaluate().getContent(); // Get modified html raw content.
// You need to replace escape characters to the standard markup because Google automatically adds escape characters to protect against cross-site scripting (XSS) attacks
var modifiedHtml = modifideHtml.replace(/(<)/ig, "<");
var modifiedHtml = modifideHtml.replace(/(>)/ig, ">");
var modifiedHtml = modifideHtml.replace(/(")/ig, '"');
var modifiedHtml = modifideHtml.replace(/(+)/ig, "+");
var html = HtmlService.createHtmlOutput(modifideHtml)
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(800)
.setHeight(600);
SpreadsheetApp.getUi().showModalDialog(html, '...');
}