79165527

Date: 2024-11-07 08:17:54
Score: 1
Natty:
Report link

I thought that this answer might be useful for understanding for resolving your issue. Auto Transfer Google sheet generated QR code to Google Doc as Image When the script of this answer is reflected in your showing script, how about the following modification?

Unfortunately, I cannot know your actual script. So, this is a simple modification. Please reflect this in your actual script.

Modified script:

Please add the following function to your script.

// ref: https://stackoverflow.com/a/71151203/7108653
var replaceTextToImage = function (body, searchText, url, width = 200) {
  var next = body.findText(searchText);
  if (!next) return;
  var r = next.getElement();
  r.asText().setText("");
  var img = r.getParent().asParagraph().insertInlineImage(0, UrlFetchApp.fetch(url).getBlob());
  if (width && typeof width == "number") {
    var w = img.getWidth();
    var h = img.getHeight();
    img.setWidth(width);
    img.setHeight(width * h / w);
  }
  return next;
};

And, please modify your script as follows.

From:

newFileBody.replaceText('<<emp-sign>>', emp_sign);
newFileBody.replaceText('<<it-sign>>', it_sign);

To:

replaceTextToImage(newFileBody, '<<emp-sign>>', emp_sign);
replaceTextToImage(newFileBody, '<<it-sign>>', it_sign);

Note:

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Blacklisted phrase (0.5): I cannot
  • RegEx Blacklisted phrase (2.5): please provide your
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • High reputation (-2):
Posted by: Tanaike