0
votes

I'm trying to edit an Avery template in google docs and populate it with information form a google sheet Via Google Apps Script.

I already body.replaceText to replace the placeholder text in the doc:

 for (var i in data) {
    var row = data[i];
    var docid = DriveApp.getFileById(templateid).makeCopy().getId();
    var doc = DocumentApp.openById(docid);
    var body = doc.getActiveSection();
    body.replaceText("%NAME%", row[0]);
    body.replaceText("%ADD_LN1%", row[1]);
    body.replaceText("%ADD_LN2%", row[2]);

The label template is a table with a drawing oval in each segment and I have inserted a text box inside the The problem i'm having that I have a text box inside the oval drawings in the doc (I need the oval drawings to know where the labels will print)

The placeholder text inside the drawing will not change when I run my script, but any test inside the table or on the page normally will change to the Google sheets information.

Here is the label template I am using: Label Page I have placed the %NAME& tag in the header, on the image and on the image that is formatted to freeze in place on page (Just in case that changes anything!)

Purpose: I have a google sheet populated with customer name address and custom choices (specific safety information to print onto a label) I then have this script insert the info into the label doc, then i can print it without having to create them from scratch every time manually.

If there isn't a way to get text / replace text that is within drawing-shape-text, is there a way I can use the circular shape as a table of as guidelines so that I can transfer across the data as standard?

If you need any more info please let me know, I'm very green and very confused.

Thank you in advance for anyone taking the time to read through this!

2
Unfortunately, in the current stage, there are not methods for directly modifying the texts in the drawing in the methods of Google Apps Script. But, when the Google Document is converted to DOCX format, the texts in the drawings can be modified. But when the Google Document is converted to DOCX format, the color of the drawings is changed. It seems that this might be due to the specification of DOCX format or Google side. I apologize for this. Even when the color of drawings is changed, when you want to replace the text, there is a workaround using Google Apps Script.Tanaike
So essentially you would like to replace all the text in the shapes with your own values? @Daedalusale13
@Tanaike thank you, is there no workaround?Daedalus
@ale13 yes , the way that a presentation slide would "shape.getText().replaceAllText" but for a google doc not a google slide.. seems so foreign to me that there aren't similar commands in each google file typeDaedalus
Thank you for replying. In the current stage, I have no idea for other workaround except for my 1st comment. This is due to my poor skill. I deeply apologize for this.Tanaike

2 Answers

0
votes

Unfortunately, in the current stage, there are not methods for directly modifying the texts in the drawing in the methods of Google Apps Script. From user - Tannaike

Google slides has the function I was looking for.

0
votes

Unfortunately, you cannot change the text inside a drawing using Apps Script.

However, as a possible workaround, you might benefit from checking the InlineDrawing Class here.

In this way, you could create a document with multiple objects of type InlineDrawing and then you could apply some of these methods:

  • setAltDescription(description) which sets the drawing's alternate description;

  • setAltTitle(title) which sets the drawing's alternate title;

  • setAttributes(attributes) which sets the element's attributes.

However, if this is not what you are looking for, you can file a feature request on Google's Issue Tracker and fill in the template here accordingly.

Reference