forked from googleworkspace/apps-script-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.gs
More file actions
111 lines (101 loc) · 3.05 KB
/
Copy pathCode.gs
File metadata and controls
111 lines (101 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* Copyright Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @OnlyCurrentDoc Limits the script to only accessing the current document.
*/
var DIALOG_TITLE = 'Example Dialog';
var SIDEBAR_TITLE = 'Example Sidebar';
/**
* Adds a custom menu with items to show the sidebar and dialog.
*
* @param {Object} e The event parameter for a simple onOpen trigger.
*/
function onOpen(e) {
DocumentApp.getUi()
.createAddonMenu()
.addItem('Show sidebar', 'showSidebar')
.addItem('Show dialog', 'showDialog')
.addToUi();
}
/**
* Runs when the add-on is installed; calls onOpen() to ensure menu creation and
* any other initializion work is done immediately.
*
* @param {Object} e The event parameter for a simple onInstall trigger.
*/
function onInstall(e) {
onOpen(e);
}
/**
* Opens a sidebar. The sidebar structure is described in the Sidebar.html
* project file.
*/
function showSidebar() {
var ui = HtmlService.createTemplateFromFile('Sidebar')
.evaluate()
.setTitle(SIDEBAR_TITLE)
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
DocumentApp.getUi().showSidebar(ui);
}
/**
* Opens a dialog. The dialog structure is described in the Dialog.html
* project file.
*/
function showDialog() {
var ui = HtmlService.createTemplateFromFile('Dialog')
.evaluate()
.setWidth(400)
.setHeight(150)
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
DocumentApp.getUi().showModalDialog(ui, DIALOG_TITLE);
}
/**
* Returns the existing footer text (if any).
*
* @return {String} existing document footer text (as a plain string).
*/
function getFooterText() {
// Retrieve and return the information requested by the sidebar.
return DocumentApp.getActiveDocument().getFooter().getText();
}
/**
* Replaces the current document footer with the given text.
*
* @param {String} footerText text collected from the client-side
* sidebar.
*/
function setFooterText(footerText) {
// Use data collected from sidebar to manipulate the document.
DocumentApp.getActiveDocument().getFooter().setText(footerText);
}
/**
* Returns the document title.
*
* @return {String} the current document title.
*/
function getDocTitle() {
// Retrieve and return the information requested by the dialog.
return DocumentApp.getActiveDocument().getName();
}
/**
* Changes the document title.
*
* @param {String} title the new title to use for the document.
*/
function setDocTitle(title) {
// Use data collected from dialog to manipulate the document.
DocumentApp.getActiveDocument().setName(title);
}