jasonoob
jasonoob

Reputation: 51

Google App Script- Docs/images in tables?

I have searched and searched for the syntax to place an image in a table cell with Google App Script in a Google Doc (not 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 yields simply the word "Blob" in my table.

I can do this all day long with a paragraph:

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

But for some reason, the "parallel" syntax in a table won't cut it? Does anyone know what I am missing?

Thank You

Upvotes: 4

Views: 2381

Answers (2)

jasonoob
jasonoob

Reputation: 51

Thank You for the input KRR.

I was able to get my project where I wanted it to go, part of which involved inserting images in a table in a Google Doc using Google App Script. After much reading, I settled on the syntax that follows. I hope this helps anyone else trying 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());
}

Upvotes: 1

KRR
KRR

Reputation: 4917

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

Hope that helps!

Upvotes: 1

Related Questions