You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|[`GetTables()`](#gettables)| Get all tables from Document. |
52
+
|[`GetValues()`](#getvalues)| Get values from a table from Document. |
53
+
|[`SetValuesBy2DArray(values [][]interface{})`](#setvaluesby2darray)| Set values to a table with 2 dimensional array. |
54
+
|[`SetValuesByObject(values []ValueObject)`](#setbaluesbyobject)| Set values to a table with an object. |
55
+
|[`DeleteTable()`](#deletetable)| Delete a table. |
56
+
|[`DeleteRowsAndColumns(d *DeleteRowsColumnsRequest)`](#deleterowsandcolumns)| Delete rows and columns of a table. |
57
+
|[`CreateTable(c *CreateTableRequest)`](#createtable)| Create new table including sell values. |
58
+
|[`AppendRow(c *AppendRowRequest)`](#appendrow)| Append row to a table by including values. |
59
+
|[`ReplaceTextsToImagesByURL(from, to string)`](#replacetexts)| Replace texts with images from URL. |
60
+
|[`ReplaceTextsToImagesByFile(from, to string)`](#replacetexts)| Replace texts with images from files on local PC. |
55
61
56
62
This library uses [google-api-go-client](https://github.com/googleapis/google-api-go-client).
57
63
@@ -78,7 +84,7 @@ About the authorization, please check the section of [Authorization](#authorizat
78
84
79
85
## Scope
80
86
81
-
In this library, using the scope of `https://www.googleapis.com/auth/documents` is recommended.
87
+
In this library, using the scope of `https://www.googleapis.com/auth/documents` is recommended. When the method of `ReplaceTextsToImagesByFile` is used, also please add `https://www.googleapis.com/auth/drive`.
82
88
83
89
<aname="gettables"></a>
84
90
@@ -355,10 +361,85 @@ When above script is run, the following result is obtained. In this case, the va
355
361
356
362

357
363
358
-
#### From:
364
+
#### To:
359
365
360
366

361
367
368
+
<aname="replacetexts"></a>
369
+
370
+
## 9. ReplaceTextsToImagesByURL and ReplaceTextsToImagesByFile
371
+
372
+
### Sample script 1
373
+
374
+
In this sample, the texts `{{sample}}` in all tables are replaced with the image retrieved by **the URL of `https://###/sample.png`**.
- The flow for replacing the text with the image on the local PC.
416
+
417
+
1. Upload the image from local PC to Google Drive.
418
+
2. Publicly share the image file. - The time for sharing is several seconds. The file is delete after the image is put.
419
+
3. Put the image using the URL of the publicly shared file.
420
+
4. Delete the image. - Even when the image is delete from Google Drive, the put image on Google Document is not deleted.
421
+
422
+
- About `SetImageSize`
423
+
> [**objectSize**](https://developers.google.com/docs/api/reference/rest/v1/documents/request#insertinlineimagerequest): The size that the image should appear as in the document. This property is optional and the final size of the image in the document is determined by the following rules: _ If neither width nor height is specified, then a default size of the image is calculated based on its resolution. _ If one dimension is specified then the other dimension is calculated to preserve the aspect ratio of the image. \* If both width and height are specified, the image is scaled to fit within the provided dimensions while maintaining its aspect ratio.
424
+
425
+
### Result
426
+
427
+
When above script is run, the following result is obtained.
428
+
429
+
#### From:
430
+
431
+

432
+
433
+
#### To:
434
+
435
+

436
+
437
+
The image of `https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-logo.png` was used as the sample image.
438
+
439
+
When `tableOnly` is `false`, the following result is retrieved.
440
+
441
+

442
+
362
443
<aname="authorization"></a>
363
444
364
445
# Authorization
@@ -535,6 +616,7 @@ func main() {
535
616
```
536
617
537
618
# Sample scripts
619
+
538
620
-[Creating a Table to Google Document by Retrieving Values from Google Spreadsheet for Golang](https://gist.github.com/tanaikech/0589a673cae9569181def8ccd10793cf)
539
621
540
622
# Limitations
@@ -574,4 +656,8 @@ If you have any questions and commissions for me, feel free to tell me.
574
656
575
657
1. When the inline objects and tables are put in the table. An error occurred. This bug was removed by this update.
576
658
659
+
- v1.1.0 (January 22, 2020)
660
+
661
+
1.[2 new methods were added.](#replacetexts) From this version, the texts can be replaced by images. The direct link and local file can be used as the image.
Copy file name to clipboardExpand all lines: methods.go
+48Lines changed: 48 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,53 @@ import (
13
13
/// Methods
14
14
///
15
15
16
+
// ReplaceTextsToImagesByURL : Replace texts to images in tables by an image URL.
17
+
//
18
+
// from: Search text
19
+
//
20
+
// to: URL of image for replacing the searched texts
21
+
//
22
+
// tableOnly: When you want to replace the texts in only table cells, please set true. When you set false, the text is searched from all body and replaced to images.
0 commit comments