Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

523
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda