Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

524
Views
How to insert images to a Google Document using AppScript?

I have a script that creates a document during runtime and attach it to a variable.

I need to insert images to it using a script.

Here is my code:

  var modulo = "foo";
  var nomeDoc = "bar";
  let doc =  DocumentApp.create("Validação escopo ("+ modulo +") cliente: " + nomeDoc);
  var body = doc.getBody();
  var imgPDF = body.appendImage(blob);

How do i pass an image as "blob" inside the variable: imgPDF?

Important: The image is in the Spreadsheet that calls this function.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

On January 19, 2022, 2 Classes for using the inner cell image were added to the Spreadsheet service. Ref But, in the current stage, the image can be put into a cell. But, unfortunately, the image in the cell cannot be retrieved. I think that this might be a bug. And also, these Classes cannot retrieve the images on a cell as the blob and the image URL. I think that this is the specification.

So, as the current workaround, I thought that in your situation, in the current stage, this method can be used. Ref

In this workaround, a Google Apps Script library might be able to be used. Ref This library can retrieve both the image in a cell and the image on a cell.

Usage:

1. Install Google Apps Script library.

You can see the method for installing this library at here.

2. Enable Drive API.

In this case, Drive API is used. So, please enable Drive API at Advanced Google services.

3. Sample script.

const spreadsheetId = "###"; // Google Spreadsheet ID
const res = DocsServiceApp.openBySpreadsheetId(spreadsheetId).getSheetByName("Sheet1").getImages();
console.log(res); // You can check the retrieved images at the log.
if (res.length == 0) return;
const blob = res[0].image.blob; // Here, 1st image of Sheet1 is retrieved. Of course, you can choose the image on the sheet.

let doc = DocumentApp.create("Validação escopo (" + modulo + ") cliente: " + nomeDoc);
var body = doc.getBody();
var imgPDF = body.appendImage(blob);
  • In this case, please declare modulo and nomeDoc.

4. Testing.

When the above script is run, the images are retrieved from "Sheet1" and put the 1st image to the created Document body.

References:

  • DocsServiceApp
  • Related thread
    • How to access new 'in-cell-image' from google apps script?
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!