forked from Rotifer/GoogleSpreadsheetProgramming_2015
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathch02.gs
52 lines (48 loc) · 1.5 KB
/
ch02.gs
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
function sayHelloAlert() {
// Declare a string literal variable.
var greeting = 'Hello world!',
ui = SpreadsheetApp.getUi();
// Display a message dialog with the greeting
//(visible from the containing spreadsheet).
// Older versions of Sheets used the Browser.msgBox()
ui.alert(greeting);
}
function helloDocument() {
var greeting = 'Hello world!';
// Create DocumentApp instance.
var doc =
DocumentApp.create('test_DocumentApp');
// Write the greeting to a Google document.
doc.setText(greeting);
// Close the newly created document
doc.saveAndClose();
}
function helloLogger() {
var greeting = 'Hello world!';
//Write the greeting to a logging window.
// This is visible from the script editor
// window menu "View->Logs...".
Logger.log(greeting);
}
function helloSpreadsheet() {
var greeting = 'Hello world!',
sheet = SpreadsheetApp.getActiveSheet();
// Post the greeting variable value to cell A1
// of the active sheet in the containing
// spreadsheet.
sheet.getRange('A1').setValue(greeting);
// Using the LanguageApp write the
// greeting to cell:
// A2 in Spanish,
// cell A3 in German,
// and cell A4 in French.
sheet.getRange('A2')
.setValue(LanguageApp.translate(
greeting, 'en', 'es'));
sheet.getRange('A3')
.setValue(LanguageApp.translate(
greeting, 'en', 'de'));
sheet.getRange('A4')
.setValue(LanguageApp.translate(
greeting, 'en', 'fr'));
}