Apps Script公式リファレンス: Apps Script Reference |障害・課題追跡: IssueTracker |Google Workspace: Status Dashboard - Summary


Creating a template copier app in Google Apps Script


This article will show you a template copier application in Google Apps Script. 
This application will automatically copy a template to your MyDrive when you access the deployed URL.

This is useful for anyone who wants to save time and effort when developing web applications with HTMLService.


When you access the deployed URL, the "OPEN FILE" link will be displayed on the screen.

The application is deployed as a web application. 
When you access the URL, the Template file, which includes, index.html, css.html and javascript.html are copied. 
A link to the file is displayed in the browser. 
Clicking the link opens the file that copied the Template.

Source Code

This code is for an application that is deployed to copy templates.
const FILE_ID = "FILE_ID";

function doGet() {
const copyFileUrl = copyFileToMydrive();
const html = '<a target="_blank" href="' + copyFileUrl + '">OPEN FILE</a>';
return HtmlService.createHtmlOutput(html);

function copyFileToMydrive() {
const file = DriveApp.getFileById(FILE_ID);
const name = "Copy of " + file.getName();
const copyFile = file.makeCopy(name);
return copyFile.getUrl();

As a template to copy from, we will prepare the following code. 
The contents of the code are up to you. 
The following is just one example, so please feel free to write it as you like.

function doGet() {
return HtmlService.createTemplateFromFile('index')

function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename).getContent();

function returnHello(name) {
return "Hello" + " " + name;

<!DOCTYPE html>
<?!= include("css"); ?>
<input type="text" id="name">
<button id="bt">submit</button>
<?!= include("javascript"); ?>

#name {
width: 10vw;
height: 5vh;
font-size: 20px;

document.getElementById("bt").onclick = runHello;

function runHello() {
var name = document.getElementById("name").value;
.withUserObject("how are you?")

function onSuccess(result, userObject) {
alert(result + " " + userObject);

function onFailure(e) {
alert([e.message, e.stack]);

This template app is as follows:


By changing the FILE_ID in, you can copy any file in Google Drive, such as scripts, spreadsheets, or documents.


Class File > makeCopy() Method

Latest post

Google Apps Scriptの障害時はIssueTrackerを見てみる - Incidents for Apps Script are reported on Issue Tracker

IssueTracker > Apps Script issues Google Apps Scriptの障害時は IssueTracker に課題が上がっていることが...