邮件合并:无法从模板追加图像 [英] Mail merge: can't append images from template

查看:100
本文介绍了邮件合并:无法从模板追加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个邮件合并功能来创建一个基于简单模板的文档。
我尝试使用以下函数来复制模板元素,但我遇到了(内嵌)图像的问题,它们始终显示为PARAGRAPH,而不是INLINE_IMAGE,并且出现以下图标而不是图像:

I'm trying to create a mail merge function to create a document based on a simple template. I tried to use the following function to copy the template elements but I'm having problems with the (inline) images, they appear always as PARAGRAPH and not INLINE_IMAGE and the following icon appears instead of the images:

以下是代码:

Here's the code:

function appendToDoc(src, dst) {
  // iterate accross the elements in the source adding to the destination
  for (var i = 0; i < src.getNumChildren(); i++) {
    appendElementToDoc(dst, src.getChild(i));
  }
}

function appendElementToDoc(doc, object)
{
    var element = object.copy();
    var type = object.getType();

    if (type == DocumentApp.ElementType.PARAGRAPH) {
        doc.appendParagraph(element);
    } else if (type == DocumentApp.ElementType.TABLE) {
      doc.appendTable(element);
    } else if (type== DocumentApp.ElementType.INLINE_IMAGE) { // This is never called :(
       var blob = element.asInlineImage().getBlob();
       doc.appendImage(blob); 
    }
}

关于如何解决这个问题的任何想法?提前致谢!

Any ideas on how to solve this? Thanks in advance!

推荐答案

据我所知,内嵌图像包含在段落中,因此我们必须检查图像类型在段落中。

As per my knowledge, inline images are included in a paragraph so we have to check for Image type in the Paragraph.

所以用于检查的代码就是这样的:

So the code for checking that would be this way:

if (type == DocumentApp.ElementType.PARAGRAPH) {
      if (element.asParagraph().getNumChildren() != 0 && element.asParagraph().getChild(0).getType() == DocumentApp.ElementType.INLINE_IMAGE) {
        var blob = element.asParagraph().getChild(0).asInlineImage().getBlob();
        doc.appendImage(blob);
      }
      else doc.appendParagraph(element.asParagraph());
    }

何PE有帮助!

这篇关于邮件合并:无法从模板追加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆