在Google Apps脚本中使用Google字体 [英] Using Google Fonts in Google Apps Scripts
问题描述
我已经看过过有关 Caja
的文档,并过滤了Google字体的使用。关于这个问题,网络上最近没有任何行动。
有人知道在通过网络应用程序创建模板页面时使用Google字体的方法吗?
我已经尝试了它在Google API页面上提供的说明,但它始终默认为默认字体。 其他帖子似乎已被闲置一段时间,我想有人可能已经想出了一种方法来解决它。
简单的解决方案,的文档(此处和 here )。我做了三件事:
- 剥离了正文和标签。这感觉很奇怪,但它工作。
- 在我的code.gs文件中将我的沙盒模式更改为IFRAME
- 将以下代码添加到html模板在code.gs文件中调用
在code.gs中:
函数doGet(){
var html = HtmlService
.createTemplateFromFile('index')
.evaluate()
.setTitle('Font测试')
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
返回html;
}
在index.html文件中:
<!DOCTYPE html>
<?// HEAD?>
< base target =_ top>
< link rel =stylesheettype =text / csshref =https://fonts.googleapis.com/css?family=Tangerine>
< style>
body {
font-family:'Tangerine',serif;
font-size:48px;
}
< / style>
<?// BODY?>
< div>字体测试< / div>
I have seen the past documentation regarding Caja
and filtering the use of Google Fonts. There hasn't been any recent action on the web regarding this issue.
Does anyone know of a way to use Google Fonts when creating a templated page via web apps?
I have tried the instructions it provides on the Google api pages but it always defaults to the default font. Other post seem to have been idle for a while and I thought someone might have figured out a way to pull it off.
Simple solution, after I read through some of the documentation (here and here). I did 3 things:
- stripped out the body and head tags. That felt very weird but it worked.
- changed my sandbox mode to IFRAME in my code.gs file
- added the following code to the html template called in the code.gs file
In code.gs:
function doGet() {
var html = HtmlService
.createTemplateFromFile('index')
.evaluate()
.setTitle('Font Test')
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
return html;
}
In index.html file:
<!DOCTYPE html>
<?// HEAD ?>
<base target="_top">
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Tangerine">
<style>
body {
font-family: 'Tangerine', serif;
font-size: 48px;
}
</style>
<?// BODY ?>
<div>Font Test</div>
这篇关于在Google Apps脚本中使用Google字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!