bcenarius
bcenarius

Reputation: 21

Inserting an image inside a table cell in Google Docs API

Is it possible to insert an image directly inside a cell in Google Docs using the API? I wanted to put an image only on the first column in a 1x2 table cell. I've read the documentation, **insertInlineImage** said: The image must be inserted inside the bounds of an existing Paragraph. For instance, it cannot be inserted at a table's start index (i.e. between the table and its preceding paragraph). Inline images cannot be inserted inside a footnote or equation.

How do I do this in Google Docs python?

Image in a Table

Upvotes: 2

Views: 496

Answers (1)

Ed Harrod
Ed Harrod

Reputation: 3619

This is possible, you can either:

  1. Use a library like https://github.com/tanaikech/gdoctableapppy to make things slightly easier
  2. Write the process yourself, the process is as follows:
    1. Insert a placeholder tag where you want your image to be inside a table, e.g. {{myImage}}
    2. Do a batch update on the document, where you:
      1. Search for this placeholder tag, and delete it
      2. Insert an inline image at the location where this tag was

One current limitation is that image must be accessible from a public URL (see docs), there is currently a feature request/bug to allow images to be uploaded too

Upvotes: 1

Related Questions