0
votes

I have a Google DOC. The DOC has embedded Google Diagrams. I'm writing a Google Script to transfer the content of the Document to a Sheet. The script goes through the document "body's children" identifying if it is a Paragraph or Table, and if it is a paragraph, extract the Text, In line drawing, or In line image.

Now, in DOCS a Diagram is represented as an image of the Diagram, not the diagram per se. Google Docs executes a request (e.g. https://docs.google.com/a/mydomain.com/drawings/d/sDanx1eRvHChcrvgj1IIdCQ/image?w=719&h=573&rev=1346&ac=1) that generates an image (terrible resolution by the way, but that a different topic). Such image is stored "somewhere" as a persistent file, and incorporated into the document via another request (e.g. filesystem:https://docs.google.com/persistent/docs/documents/1DlxAjdWZAVOkGvq1CZvsbEpxBNs8bDCPW1972UKfbxU/drawing/sDanx1eRvHChcrvgj1IIdCQ?zx=xxuxts66tny4). Neither are regular straight-forward URLs to an image.

The '=IMAGE' function and other Google "dialog screens" (like Insert image from URL in Docs) will NOT resolve them. The preference to use '=IMAGE' is that the image remains with the cell.

Furthermore, the INLINE IMAGE type appears not to provide a method to even acquire these URLs, or the Diagram's document ID. Even if I could get the URLs, using the URLs directly or 'fetching' them to create a Blob from them, I only see they would be useful with the InsertImage method, which would leave the image detached from a cell.

Apparently, even using the URL that generates the Image with the insertImage(blob), fails saying there was a server error.

Any ideas?

1
Not sure I got you. I'm not intending to publish anything to the web. I just want to somehow come to generate an image URL from the Google Drawing embedded in the Google Doc that is consumable by the =IMAGE function within a Google Sheet via a Google Script. My documents are all inside my company's Google Domain. Can you please rephrase your question?iatorresc

1 Answers

0
votes

If your embedded images have links you could use getLinkUrl(). Google Apps Script hasn't a method to get directly the URL of an embedded drawing.

I didn't tested this yet, put I think that it should work.

As the Google Sheet function IMAGE requires an URL of a publicly accessible image, when you be preparing your Google drawings that will be used on a spreadsheet,

  1. publish the drawing to the web
  2. grab the URL of the published image
  3. add the Google drawing to the document
  4. add the URL of the published image as a link to the embedded image

Then when you be transferring the content from the Google document to a Google spreadsheet you could use getLinkUrl() to get the URL and add it as parameter of IMAGE