能否对HtmlService及HtmlOutput对话框中的文本进行格式设置?
完全可以调整对话框的样式,Google Apps Script的HtmlService支持在传入的HTML内容中内嵌CSS自定义所有样式属性,包括字体、背景色、文字格式、边距等。
你可以参考以下修改后的代码实现自定义样式:
var htmlOutput = HtmlService .createHtmlOutput(` <style> * { box-sizing: border-box; margin: 0; padding: 0; } body { /* 自定义字体,替换为你需要的字体即可 */ font-family: "微软雅黑", "PingFang SC", Arial, sans-serif; /* 自定义背景色 */ background-color: #f8f9fa; padding: 40px 25px; } .tip-text { font-size: 16px; line-height: 1.8; color: #2c3e50; text-align: center; margin-top: 30px; } </style> <p class="tip-text">请稍候,我们正在处理您的请求,该过程可能需要数分钟。处理期间请勿刷新页面,感谢您的配合…</p> `) .setWidth(550) .setHeight(300); SpreadsheetApp.getUi().showModalDialog(htmlOutput, '请求处理中'); var res = apiCall(sheet.getRange(cell).offset(0,1).getA1Notation(),msisdn,msisdnd_list,sheet); var output = HtmlService.createHtmlOutput('<script>google.script.host.close();</script>'); SpreadsheetApp.getUi().showModalDialog(output, '请求处理完成!');
你可以按需调整以下常用样式参数:
- 字体:修改
font-family属性的取值,填写你需要的字体名称即可 - 背景:修改
background-color的色值,支持纯色、渐变等所有CSS支持的背景效果 - 文字样式:可自由调整
font-size(字号)、color(文字颜色)、text-align(对齐方式)、line-height(行高)等属性 - 扩展内容:还可以额外添加加载动画、进度图标等元素,直接在HTML部分插入对应标签和样式即可
内容的提问来源于stack exchange,提问作者ultraMatt386
相关产品推荐
相关产品推荐

