0
votes

I wrote a script that takes some data from a google spreadsheet and writes it in several separate tables in a google document. Since I need to physically cut these tables from the printed document, I'd like to add horizontal lines between them. I guess I can insert an image of a line, via

var cutline = UrlFetchApp.fetch("SOME URL");
body.appendInlineImage(resp.getBlob());

where "SOME URL" is the url for the image.

Another way I can think of would be creating a one-column table and add my tables in its cells. The horizontal lines for the table would be my cutting guides.

However, from the user interface I a horizontal line can be easily added via "Insert>Horizontal Line". I was not able to do find a way to do that from Google Apps Script.

Is this unsupported?

Can someone confirm that and/or possibly suggest method that is less cumbersome than those I thought of?

EDIT: I have also found the HorizontalRule class, which I do not understand entirely. However I don't think it's what I'm looking for. Another alternative could be an InlineDrawing. However, from this guide, I gather that an InlineDrawing can only be manipulated, but not added programmatically.

1
Hi Ruben, please read my question. I'm not asking how to insert an image in a document. In fact, I'm proposing that as a possible alternative to what I'm looking for. I'm asking whether it's possible to insert a line as one does from the menu in the user interface (or possible alternative, if that's not possible). - PFB

1 Answers

2
votes

HorizontalRule should do the magic. This code worked for me:

DocumentApp.getActiveDocument().getBody().appendHorizontalRule();

More info: https://developers.google.com/apps-script/reference/document/horizontal-rule#copy()