Skip to content

Commit b2f4644

Browse files
Merge pull request #65 from contributorpw/edits
2 parents 99dc027 + 62ff0a8 commit b2f4644

File tree

11 files changed

+14548
-4080
lines changed

11 files changed

+14548
-4080
lines changed

package-lock.json

Lines changed: 14431 additions & 4066 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
"devDependencies": {
2121
"@babel/core": "^7.12.10",
2222
"@babel/preset-env": "^7.12.11",
23-
"@google/clasp": "^2.3.0",
2423
"@types/google-apps-script": "^1.0.20",
2524
"@types/lodash": "^4.14.165",
2625
"babel-plugin-transform-es5-property-mutators": "^6.24.1",
2726
"del": "^6.0.0",
2827
"eslint": "^7.16.0",
2928
"eslint-config-google": "^0.14.0",
30-
"eslint-config-prettier": "^7.1.0",
29+
"eslint-config-prettier": "^8.1.0",
3130
"eslint-plugin-googleappsscript": "^1.0.3",
3231
"eslint-plugin-prettier": "^3.3.0",
32+
"forked-clasp": "^2.11.2",
3333
"got": "^11.8.1",
3434
"gulp": "^4.0.2",
3535
"gulp-file-include": "^2.3.0",

snippets/calendar/clear-all-events/index.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
/* exported run */
2-
3-
/**
4-
*
5-
*/
6-
function run() {
7-
const calendar = CalendarApp.getCalendarById(
8-
'1fq7choqdctaal2sk5i5du43qc@group.calendar.google.com'
9-
);
10-
console.log(clearAllEvents_(calendar));
11-
}
12-
131
/**
142
*
153
* @param {GoogleAppsScript.Calendar.Calendar} calendar
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+
### Run it
22+
23+
{{< codeFromFile "run.js" >}}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* global clearAllEvents_ */
2+
3+
/**
4+
*
5+
*/
6+
function run() {
7+
const calendar = CalendarApp.getCalendarById(
8+
'1fq7choqdctaal2sk5i5du43qc@group.calendar.google.com'
9+
);
10+
console.log(clearAllEvents_(calendar));
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"timeZone": "Europe/Moscow",
3+
"exceptionLogging": "STACKDRIVER",
4+
"runtimeVersion": "V8"
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "container-bound-sheet",
3+
"src": []
4+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Removes all links from the range
3+
*
4+
* @param {GoogleAppsScript.Spreadsheet.Range} range A range
5+
* @return {GoogleAppsScript.Spreadsheet.RichTextValue[][]}
6+
*/
7+
function unlinkUrls_(range = SpreadsheetApp.getActiveRange()) {
8+
return range.setRichTextValues(
9+
range.getRichTextValues().map((rowRichTextValues) =>
10+
rowRichTextValues.map((richTextValue) => {
11+
let copy;
12+
if (richTextValue.getRuns().some((ruin) => ruin.getLinkUrl())) {
13+
copy = richTextValue.copy();
14+
copy.setLinkUrl(undefined);
15+
return copy.build();
16+
}
17+
return richTextValue;
18+
})
19+
)
20+
);
21+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: 'Unlink all URLs in the range'
3+
date: '2021-04-12'
4+
description: 'Using the RichTextValues for clearing a specific range'
5+
tags: ['sheets', 'Sheets advanced service']
6+
categories: ['snippets']
7+
images: ['./snippets/sheets/unlink_urls/screenrecord.gif']
8+
---
9+
10+
{{< toc >}}
11+
12+
## Unlink all URLs in the range
13+
14+
![Snippet of Unlink all URLs in the range](./screenrecord.gif)
15+
16+
### Snippet
17+
18+
- {{< externalLink >}}
19+
- {{< commentLink >}}
20+
- {{< scrvizLink >}}
21+
22+
{{< codeFromFile "index.js" >}}
23+
24+
### Run it
25+
26+
{{< codeFromFile "run.js" >}}
27+
28+
### Issues
29+
30+
This code does not remove links if they are the only content in the cell. See [google apps script - Unlink all hyperlinks from a sheet - Stack Overflow](https://stackoverflow.com/questions/62271646/unlink-all-hyperlinks-from-a-sheet/62275201#62275201)

snippets/sheets/unlink_urls/run.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* global unlinkUrls_ */
2+
3+
/**
4+
* Runs the snippet.
5+
* Unlink URLs
6+
*/
7+
function run() {
8+
const sheet = SpreadsheetApp.getActiveSheet();
9+
const range = sheet.getDataRange();
10+
unlinkUrls_(range);
11+
}
12+
13+
/**
14+
* Create menu for handy use
15+
*/
16+
function onOpen() {
17+
SpreadsheetApp.getUi()
18+
.createMenu('Apps Script Snippets')
19+
.addItem('Unlink all urls on the Sheet', 'run')
20+
.addToUi();
21+
}

0 commit comments

Comments
 (0)