0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GAS HTML作成

Posted at

概要

スプレッドシートの内容をHTMLに反映させるGASのスクリプト

GAS
function createHtmlFromSheet(){
  // 定数
  const SHEET_NAME = 'シート名';
  const HTML_TEMPLATE = 'index' // html名

  // 対象のシートから情報を取得する
  let spreadSheet = spreadSheetApp.getActiveSpreadsheet();
  let targetSpreadSheet = spreadSheet.getSheetByName(SHEET_NAME);
  let contents = targetSpreadSheet.getRange(1,1,1,1).getValues();

  let html = HtmlService.createTemplateFromFile(HTML_TEMPLATE);
  html.contents = contents;

  // HTML吐き出し(マイドライブ上)
  let fileName = 'test.html';
  let content = html.evaluate().getContent();
  let mineType = MineType.HTML;
  DriveApp.createFile(fileName, content, mineType);
}
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset='utf-8'>
  <meta http-equiv='X-UA-Compatible' content='IE=edge'>
  <title>Page Title</title>
  <meta name='viewport' content='width=device-width, initial-scale=1'>
  <link rel='stylesheet' type='text/css' media='screen' href='main.css'>
  <script src='main.js'></script>
</head>
<?
  let a = contents[0][0];
  let b = contents[0][1];
  let c = contents[0][2];
?>
<body>
  <p><?= a?></p>
  <p><?= b?></p>
  <p><?= c?></p>
</body>
</html>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?