File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed
snippets/docs/insert_image Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "timeZone" : " Europe/Moscow" ,
3+ "exceptionLogging" : " STACKDRIVER" ,
4+ "runtimeVersion" : " V8"
5+ }
Original file line number Diff line number Diff line change 1+ {
2+ "type" : " container-bound-doc" ,
3+ "src" : []
4+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments