Google Script App - Docs / Images in Sheets?

I have searched and searched for a syntax for placing an image in a spreadsheet cell with Google App Script in a google doc (not a sheet). This is what I am trying to do:

var resp01 = UrlFetchApp.fetch("http://www.example.com/image01.png");
var resp02 = UrlFetchApp.fetch("http://www.example.com/image02.png");

var cells = [[resp01.getBlob()], [resp02.getBlob()]];
copyBody.appendTable(cells);

      

This just gives the word "Blob" in my table.

I can do this all day long with a paragraph:

Body.getChild(x).asParagraph().appendInlineImage(resp01.getBlob());

      

But somehow the "parallel" syntax in the table won't truncate it? Does anyone know what I am missing?

thank

+3


source to share


2 answers


You need to call the TableCell insertImage () method and provide the child index and blob source of the image as parameters.



Hope it helps!

+1


source


Thanks for entering KRR.

I managed to get my project where I wanted, and some of them involved inserting images into a spreadsheet in Google Doc using a Google Script app. After reading a lot, I settled on the following syntax. Hope this helps someone else to learn:



function createDoc() {
  var doc = DocumentApp.create('Sample Document');
  var body = doc.getBody();
  var resp01 = UrlFetchApp.fetch("http://www.cincinnati-oh.gov/cityofcincinnati/assets/Image/Logos/cityofcincinnati.png");

  var rowsData = [["City of Cincinnati IMAGE:", ""]];
    table = body.insertTable(1, rowsData);
    var row = table.getRow(0);
    var cell = row.getCell(1);
    cell.appendImage(resp01.getBlob());
}

      

0


source







All Articles