【问题标题】:How to copy images in google docs paragraphs rigth?如何正确复制谷歌文档段落中的图像?
【发布时间】:2020-08-05 23:29:17
【问题描述】:

由于此topic 的答案,我可以将内容表单模板文档复制到另一个保存所有格式的文档。
但是当我在几个段落中添加一些图片时,结果文档将图片显示为图片徽标

问题是如何以这种方式正确复制图像?

【问题讨论】:

    标签: google-apps-script google-docs


    【解决方案1】:

    您需要调整您的 insert 方法以适应每种不同的元素类型...

    一个例子可能是这样的:

    function copyElementsByType() {
      var sourceDoc = DocumentApp.openById('yyyy');
      var targetDoc = DocumentApp.openById('xxxx');;
      var bodyS = sourceDoc.getBody();
      var otherBody = targetDoc.getBody()();
      var elements = bodyS.getNumChildren()
      for( var e=0;e<elements;e++) {
        var element = otherBody.getChild(e).copy();
        var type = element.getType();
        if( type == DocumentApp.ElementType.PARAGRAPH ){
          body.insertParagraph(e,element)}
        else if( type == DocumentApp.ElementType.TABLE ){
          body.insertTable(e,element)}
        else if( type == DocumentApp.ElementType.LIST_ITEM ){
          body.insertListItem(e,element)}
        else if( type == DocumentApp.ElementType.INLINE_IMAGE ){
          body.insertImage(e,element)
        } else {
          throw new Error("check what to do with this type of element : "+type);
        }
      }
    }
    

    【讨论】:

    • 哦,谢谢!你给我指路。另外必须说我必须进入更深的层次。
    • 就是这个想法……根据您的用例的需要,越深入越好!不过,你能接受它作为一个有效的答案吗?谢谢
    • 当然。但一个有趣的薄 - 当我让图像文本包装我可以得到图像!我想我应该再问一个问题。
    • 谢谢 :-) 我认为这实际上是一个错误,没有非内联图像的方法...我会尝试在这里找到问题参考和更新。
    • 谢谢。我试图插入图像并通过代码使其文本换行,但也找不到这样的方法(((
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-15
    • 2016-06-20
    • 2014-07-16
    • 1970-01-01
    相关资源
    最近更新 更多