I want to create a connection between my Google Sheets and Google Docs so that when I update a cell value in the spreadsheet, it automatically updates the corresponding text in my document. I’m trying to use Google Apps Script for this but my code isn’t working properly. Here’s what I’ve attempted so far:
var spreadsheet = SpreadsheetApp.openById("");
var worksheet = spreadsheet.getSheetByName('Sheet1');
var cell = worksheet.getRange('B3');
var cellValue = cell.getValue();
var document = DocumentApp.openById("");
const docBody = document.getBody();
docBody.replaceText('{{UserName}}', cellValue);
I think there might be an issue with how I’m getting the cell value or maybe the way I’m trying to replace the text. Can someone help me figure out what’s wrong with my approach?