Using Google Fonts in Google Apps Scripts

非 Y 不嫁゛ 提交于 2019-12-25 03:54:50

问题


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.


回答1:


Simple solution, after I read through some of the documentation (here and here). I did 3 things:

  1. stripped out the body and head tags. That felt very weird but it worked.
  2. changed my sandbox mode to IFRAME in my code.gs file
  3. 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>


来源:https://stackoverflow.com/questions/35935748/using-google-fonts-in-google-apps-scripts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!