Skip to content

Commit 697561a

Browse files
Inits some samples. Fixes (#88)
* edits: init minimal workspace Signed-off-by: Alex Ivanov <ai@contributor.pw> * edits: init file uload to drive Signed-off-by: Alex Ivanov <ai@contributor.pw> * fix(content): change dragg down Signed-off-by: Alex Ivanov <ai@contributor.pw>
1 parent 348af02 commit 697561a

File tree

9 files changed

+195
-3
lines changed

9 files changed

+195
-3
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"timeZone": "Europe/Moscow",
3+
"dependencies": {},
4+
"exceptionLogging": "STACKDRIVER",
5+
"runtimeVersion": "V8",
6+
"oauthScopes": [
7+
"https://www.googleapis.com/auth/drive.addons.metadata.readonly"
8+
],
9+
"addOns": {
10+
"common": {
11+
"name": "Google Apps Script Snippets",
12+
"logoUrl": "https://www.gstatic.com/images/icons/material/system/1x/pets_black_48dp.png",
13+
"homepageTrigger": {
14+
"runFunction": "onHomepage",
15+
"enabled": true
16+
}
17+
},
18+
"docs": {},
19+
"sheets": {},
20+
"slides": {},
21+
"gmail": {},
22+
"drive": {
23+
"onItemsSelectedTrigger": {
24+
"runFunction": "onDriveItemsSelected"
25+
}
26+
},
27+
"calendar": {}
28+
}
29+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "standalone"
3+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* On Homepage event trigger
3+
*
4+
* @param {GoogleAppsScript.Addons.EventObject} e Event Object
5+
* @returns {GoogleAppsScript.Card_Service.Card}
6+
*/
7+
function onHomepage(e) {
8+
return createTextCard();
9+
}
10+
11+
/**
12+
* On Drive item selected event trigger
13+
*
14+
* @param {GoogleAppsScript.Addons.EventObject} e Event Object
15+
* @returns {GoogleAppsScript.Card_Service.Card}
16+
*/
17+
function onDriveItemsSelected(e) {
18+
const items = e.drive.selectedItems;
19+
const text = items.map((driveItem) => driveItem.title).join('\n');
20+
return createTextCard(text);
21+
}
22+
23+
/**
24+
* Create Card
25+
*
26+
* @param {string} text Text
27+
* @param {boolean} isHomepage
28+
* @returns {GoogleAppsScript.Card_Service.Card}
29+
*/
30+
function createTextCard(text, isHomepage) {
31+
const message = isHomepage ? `HOMEPAGE\n${text}` : `${text}`;
32+
const textWidget = CardService.newTextParagraph().setText(message);
33+
const section = CardService.newCardSection().addWidget(textWidget);
34+
const card = CardService.newCardBuilder().addSection(section);
35+
return card.build();
36+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: 'To clear all events from a Google Calendar'
3+
date: '2021-03-29'
4+
description: 'Loops through all events and removes them. Demonstrates differences in event types.'
5+
tags: ['calendar']
6+
categories: ['snippets']
7+
---
8+
9+
{{< toc >}}
10+
11+
## Clear all events from a Calendar
12+
13+
### Snippet
14+
15+
- {{< externalLink >}}
16+
- {{< commentLink >}}
17+
- {{< scrvizLink >}}
18+
19+
{{< codeFromFile "index.js" >}}
20+
21+
### Manifest
22+
23+
{{< codeFromFile "appsscript.json" >}}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"timeZone": "Europe/Moscow",
3+
"dependencies": {},
4+
"exceptionLogging": "STACKDRIVER",
5+
"runtimeVersion": "V8",
6+
"oauthScopes": [
7+
"https://www.googleapis.com/auth/drive.addons.metadata.readonly"
8+
],
9+
"addOns": {
10+
"common": {
11+
"name": "Google Apps Script Snippets",
12+
"logoUrl": "https://www.gstatic.com/images/icons/material/system/1x/pets_black_48dp.png",
13+
"homepageTrigger": {
14+
"runFunction": "onHomepage",
15+
"enabled": true
16+
}
17+
},
18+
"docs": {},
19+
"sheets": {},
20+
"slides": {},
21+
"gmail": {},
22+
"drive": {
23+
"onItemsSelectedTrigger": {
24+
"runFunction": "onDriveItemsSelected"
25+
}
26+
},
27+
"calendar": {}
28+
}
29+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "standalone"
3+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* On Homepage event trigger
3+
*
4+
* @param {GoogleAppsScript.Addons.EventObject} e Event Object
5+
* @returns {GoogleAppsScript.Card_Service.Card}
6+
*/
7+
function onHomepage(e) {
8+
return createTextCard();
9+
}
10+
11+
/**
12+
* On Drive item selected event trigger
13+
*
14+
* @param {GoogleAppsScript.Addons.EventObject} e Event Object
15+
* @returns {GoogleAppsScript.Card_Service.Card}
16+
*/
17+
function onDriveItemsSelected(e) {
18+
const items = e.drive.selectedItems;
19+
const text = items.map((driveItem) => driveItem.title).join('\n');
20+
return createTextCard(text);
21+
}
22+
23+
/**
24+
* Create Card
25+
*
26+
* @param {string} text Text
27+
* @param {boolean} isHomepage
28+
* @returns {GoogleAppsScript.Card_Service.Card}
29+
*/
30+
function createTextCard(text, isHomepage) {
31+
const message = isHomepage ? `HOMEPAGE\n${text}` : `${text}`;
32+
const textWidget = CardService.newTextParagraph().setText(message);
33+
const section = CardService.newCardSection().addWidget(textWidget);
34+
const card = CardService.newCardBuilder().addSection(section);
35+
return card.build();
36+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: 'To clear all events from a Google Calendar'
3+
date: '2021-03-29'
4+
description: 'Loops through all events and removes them. Demonstrates differences in event types.'
5+
tags: ['calendar']
6+
categories: ['snippets']
7+
---
8+
9+
{{< toc >}}
10+
11+
## Clear all events from a Calendar
12+
13+
### Snippet
14+
15+
- {{< externalLink >}}
16+
- {{< commentLink >}}
17+
- {{< scrvizLink >}}
18+
19+
{{< codeFromFile "index.js" >}}
20+
21+
### Manifest
22+
23+
{{< codeFromFile "appsscript.json" >}}

snippets/sheets/spreadsheet-dragg_down_formulas/dragg_down_formulas.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@
88
*/
99
function run() {
1010
const sheet = SpreadsheetApp.getActiveSheet();
11-
const base = sheet.getRange('C3:C');
11+
const base = sheet.getRange('I3:I');
1212
const colFormula = sheet.getRange('J3');
1313
draggDownFormulas_(base, colFormula);
1414
}
1515

16+
function runBulk() {
17+
const formulasCells = ['J3', 'K3', 'M3'];
18+
const sheet = SpreadsheetApp.getActiveSheet();
19+
const base = sheet.getRange('I3:I');
20+
formulasCells.forEach((cell) => {
21+
const colFormula = sheet.getRange(cell);
22+
draggDownFormulas_(base, colFormula);
23+
});
24+
}
25+
1626
/**
1727
* User action. Runs the snippet
1828
*/
@@ -30,7 +40,7 @@ function run2() {
3040
function draggDownFormulas_(base, colFormula) {
3141
const baseValues = base.getValues();
3242
const lastBase =
33-
baseValues.length - baseValues.reverse().findIndex(row => row[0] !== '');
43+
baseValues.length - baseValues.reverse().findIndex((row) => row[0] !== '');
3444
const colFormulaFormula = colFormula.getFormula();
3545
colFormula
3646
.getSheet()
@@ -50,7 +60,7 @@ function draggDownFormulas_(base, colFormula) {
5060
function draggDownOneFormula_(base, colFormula) {
5161
const baseValues = base.getValues();
5262
const lastBase =
53-
baseValues.length - baseValues.reverse().findIndex(row => row[0] !== '');
63+
baseValues.length - baseValues.reverse().findIndex((row) => row[0] !== '');
5464
const colFormulaFormula = colFormula.getFormula();
5565
colFormula
5666
.getSheet()

0 commit comments

Comments
 (0)