Google Docs API call to insert content from one Google Doc into another

Hello Makers,

I’m trying to insert a table into a Google Docs. Because the Google Docs API is too complex for my skill level, I’m first creating the table inside an empty Google Docs using HTML.

How I’m wondering how to:

  1. Determine the position in the second multi-page document where it is to be inserted.
  2. The actual API call to insert the content of the first Doc.

Any experts on this around? I realize it’s more of a Google Docs than Make topic… Apollogies

Hi @Zbulo,
I’ve worked quite a lot with Google Docs but I have to admit I didn’t insert a table yet.
Usually the process you do seems quite logical. Try to create a template using variables {{var1}} {{name}}, {{price}}. You can then use “Create Document from Template” and fill in these variables.

Is this a solution that fits for you?

Best,
Richard

Thanks Richard, I’m not sure I got this right.

To build the table rows, I’m looping through multiple Airtable records. I aggregator the HTML rows and insert them into the table that is part of the “Create Document from Template” step.

I’m failing at the second step, to pin point the location inside and insert the table from the first into the second document. Here I got stuck with the Google Docs API.

Okay, sorry! :smiley: I see what you are doing there but on the screenshot there is only the first step which is successful?
So the issue happens after the screenshot?

Exactly, the second I don’t manage to implement.

Alright, I see.
How is the second document built or what is inside the second document? You said it’s multiple pages but do you have a variable within this document? How would you manually determine the position of the table within that document?
Is there something specific we can search for?

It’s a generic contract type of document filled with variables.
I can add whatever orientation point is easiest to discover by the workflow.
E.g. for example a chapter head with a certain number, title, symbol…
Open for any ideas. :slight_smile:

@Zbulo, I am super sorry! :slight_smile: I don’t really get it without seeing it. :confused:

Why don’t you put {{table}} and put it in there? Why do you even need to create two documents and “merge” them afterwards?

No worries Richard, this is nasty stuff. :wink:

My knowledge is too limited to use the Google Docs API to insert the table.

At the same time one cannot insert a formatted table via a variable.

HTML conversion only works when creating a new document / not from template.

Aaaah okay, I didn’t know that.
And the table always looks the same? Or does it have a different amount of columns/rows each time?

Rows are variable and always change.

But columns stay the same? Because I’ve looked into the documentation of Google Docs and it seems like you could have a table in the Document and then add/remove or update rows.

Yes, columns are static, yet the API is very complex for me to use and produce a myriad of errors I don’t manage to debug. In another thread, someone had the smart solution of reversing the content order, which appears to remove many of the pixel / placement issues.

@Zbulo While working on a similar project, I found it very difficult to modify an existing Google Doc after creating one from a template.

A potential approach though could be of instead of modifying a document is to create a new (v2) of the document using the steps above.

1 Like

Hey @Zbulo, I’ve done this a fair few times

After your text aggregator, you want to get rid of the Create a Document module.

Instead, use a Set a Variable module under the Tools pack.

Name your variable Table HTML, and have your crafted HTML variable as the value

Next, and this is directly in your second google doc (so outside of Make) , wherever you want the table to sit in the page, put a very unique text, maybe something like <<|TABLEINSERT|>>

Come back to Make, and after your Set a Variable module, you’ll use the Download a Document module

Download it as HTML format as per screenshot above.

Directly after that module, you will use the Create a Document module.

In here, you will do something like the below

And voila!

3 Likes

Thanks for the input! I will give this a try, a very smart and crafty workaround. :slight_smile:

1 Like

Followed the instructions by @D-EFFCON and works beautifully. :+1:

2 Likes

Glad to hear that! :slight_smile:

1 Like

@D-EFFCON This is such a creative way to insert a table into a Google doc :+1:

Thanks for sharing

1 Like