如何在Google文档段落中复制图片? [英] How to copy images in google docs paragraphs rigth?

查看:748
本文介绍了如何在Google文档段落中复制图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于这个的答案主题我可以将内容表单模板文档复制到另一个保存所有格式。

但是,当我将几张图片添加到几段文字后,结果文档将图片显示为图片标志


问题是如何在这种方式下复制图像?

解决方案

您需要调整您的插入方法到每个不同的元素类型......



一个例子可能是这样的:

  function copyElementsByType(){
var sourceDoc = DocumentApp.openById( 'YYYY');
var targetDoc = DocumentApp.openById('xxxx');;
var bodyS = sourceDoc.getBody();
var otherBody = targetDoc.getBody()(); $ var $ element = 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错误(检查如何处理这种类型的元素:+ type);
}
}
}


Due the answer on this topic I can copy content form template doc to another saving all formatting.
But when I add some pictures to couple of paragraphs the result document shows pictures as picture logo

The question is how to copy images right on this way?

解决方案

You need to adapt your insert method to every different element type...

an example could be like this :

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);
    }
  }
}

这篇关于如何在Google文档段落中复制图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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