I’m working on automating a label creation process using Google Apps Script. I have a Google Docs template with oval drawings that contain text boxes, and I need to populate these with data from a Google Sheet.
My current script successfully replaces placeholder text in the main document body:
function updateLabels() {
var spreadsheetData = getSheetData();
for (var index = 0; index < spreadsheetData.length; index++) {
var currentRow = spreadsheetData[index];
var newDocId = DriveApp.getFileById(originalTemplate).makeCopy().getId();
var document = DocumentApp.openById(newDocId);
var mainBody = document.getActiveSection();
mainBody.replaceText("{{CUSTOMER_NAME}}", currentRow[0]);
mainBody.replaceText("{{ADDRESS_LINE1}}", currentRow[1]);
mainBody.replaceText("{{ADDRESS_LINE2}}", currentRow[2]);
}
}
The issue is that placeholder text inside the drawing shapes doesn’t get replaced. The script works fine for regular text in tables or paragraphs, but completely ignores text within drawing elements.
I’m trying to create an automated workflow where customer information from a spreadsheet gets inserted into label templates, eliminating manual copy-paste work. The oval shapes serve as visual guides for where labels will be printed.
Is there any way to access and modify text content within drawing shapes using Google Apps Script? If not, are there alternative approaches to achieve similar visual formatting while keeping the text accessible to the script?
Hit this exact issue six months ago building an automated invoice system. Google Apps Script treats drawing shapes like black boxes - you can see they’re there but can’t touch any text inside them. The DocumentApp API just doesn’t handle embedded objects the same way as regular text elements. Instead of fighting it, I switched to positioned text elements with styling that mimics ovals. Make a single-cell table, add heavy border radius with custom CSS, and drop it where your drawing would go. Text stays scriptable and looks almost identical. Another option that worked well: use the Google Drawings API separately to create shapes with text, then insert the finished drawings into your document. More complex setup but keeps your exact visual requirements while staying automated.
Nope, Google Apps Script can’t access or change text inside drawing shapes in Google Docs. The DocumentApp API is pretty limited with drawings - it can see they’re there but can’t touch the text inside them. I hit this same wall when trying to automate certificate generation. My workaround was to ditch the drawing shapes for formatted text boxes using tables with custom styling. You can get similar oval effects with table cells that have rounded borders and background colors through CSS styling in HTML service, then drop that formatted content into your document. Another option is switching to Google Slides for your templates since the SlidesApp API handles shape manipulation way better. Generate your labels in Slides, then export or print from there. You keep the visual formatting you want while your script can actually modify the text programmatically.
Nope, can’t be done - Google Docs drawings are locked boxes that Apps Script can’t access. Hit this same wall when automating wedding invitations last year. I switched to textboxes with heavy CSS styling instead of drawing shapes. You lose some visual polish but get full script control.