Skip to content

Commit 2ebc25b

Browse files
Merge pull request #83 from contributorpw/edits
Edits
2 parents bf292b6 + 3b9c441 commit 2ebc25b

File tree

7 files changed

+74
-0
lines changed

7 files changed

+74
-0
lines changed

snippets/common_ui/open_url_in_browser/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ This may not always work as browsers protect tabs from opening spontaneously.
1818
{{< codeFromFile "index.js" >}}
1919
{{< codeFromFile "app.html" >}}
2020
{{< codeFromFile "appsscript.json" >}}
21+
22+
{{< clipboard >}}
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-doc",
3+
"src": []
4+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @param {GoogleAppsScript.Document.InlineImage} docImage
3+
* @returns {GoogleAppsScript.Document.InlineImage} docImage
4+
*/
5+
const scaleImage_ = (docImage, { width = undefined, height = undefined }) => {
6+
const factor = docImage.getHeight() / docImage.getWidth();
7+
if (width && height) docImage.setWidth(width).setHeight(height);
8+
else if (width) {
9+
docImage.setWidth(width).setHeight(width * factor);
10+
} else docImage.setWidth(height / factor).setHeight(height);
11+
return docImage;
12+
};
13+
14+
/**
15+
*
16+
*/
17+
function run() {
18+
const image = DriveApp.getFileById('1nVNdbt9SY42c-A30X5iSK4RaMcKCk2pt');
19+
const paragraph = DocumentApp.getActiveDocument()
20+
.getBody()
21+
.getTables()[0]
22+
.getRow(0)
23+
.getCell(1)
24+
.getChild(0)
25+
.asParagraph(); // The paragraph in a specific cell
26+
const inlineImage = paragraph.insertInlineImage(0, image.getBlob());
27+
scaleImage_(inlineImage, { width: 200 });
28+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"timeZone": "Europe/Moscow",
3+
"dependencies": {
4+
"enabledAdvancedServices": [
5+
{
6+
"userSymbol": "Drive",
7+
"version": "v2",
8+
"serviceId": "drive"
9+
}
10+
]
11+
},
12+
"exceptionLogging": "STACKDRIVER",
13+
"runtimeVersion": "V8"
14+
}
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
*
3+
*/
4+
function convert() {
5+
const blob = UrlFetchApp.fetch(
6+
'https://file-examples-com.github.io/uploads/2017/02/file_example_XLS_10.xls'
7+
).getBlob();
8+
9+
const file = DriveApp.createFile(blob);
10+
Drive.Files.copy(
11+
{
12+
title: 'New file',
13+
},
14+
file.getId(),
15+
{ convert: true }
16+
);
17+
file.setTrashed(true);
18+
}

0 commit comments

Comments
 (0)