2016-05-13 6 views
0

GDocのコンテンツを別のGDocにコピーしようとしています。これは、すべての異なる要素タイプに対して非常にうまく機能します。テーブルを含む(Enum DocumentApp.ElementType.TABLE)。ただし、テーブルにインラインイメージ(Enum DocumentApp.ElementType.INLINE_IMAGE)が含まれている場合、イメージは正しくコピーされません。app-script google docインライン画像付きコピーテーブル

ここにソースGDocの例へのリンクがあります。 https://docs.google.com/document/d/14kXjC0CTkEgmD7Ttv0YKL9ubfDRHbL1hCVOqOiyiEDU/edit#。テーブルの列をニュージーランドの旗で探します。フラグはターゲットGDocの新しいテーブルに正しくコピーされません。

私はソースドキュメント内のテーブルオブジェクトを見つけて、Body :: insertTable(childIndex、table)を使用してターゲットGDocのBodyに挿入しています。テーブルの他のほとんどの要素はOKをコピーします。埋め込みGoogle描画を含む。しかし、インラインイメージではありません。

答えて

0

インラインイメージをコピーする方法は、Class InlineImageにあり、インラインイメージがListItemまたはParagraphに含まれている場合は、さらに別の方法があります。

0

私も同様の問題がありました。私の場合、番号付きリストのGLYPH_TYPEも失われてしまいました。 しかし、CellChildrenを1つずつコピーすると画像が正常にコピーされることが検出されました。

私は新しいテーブルを全体的にコピーしてから、各dstTableセルの内容を元のテーブルから1つずつ置き換えて問題を解決しました。

テーブル内の別のテーブルが検出された場合、この関数はそれ自身を呼び出しますので、これはネストしたテーブルでも正常に機能します。 また、挿入後に属性を追加設定することで、失われたListItem属性の問題も解決されます。ここで

は私も働いコードセグメントである:

は、まず私は、テーブルを検出し、dstBodyに挿入...

... 
dstChild = srcChild.copy(); 
switch(dstChild.getType()) { 
    case DocumentApp.ElementType.PARAGRAPH: 
    ... 
    case DocumentApp.ElementType.LIST_ITEM: 
    ... 
    case DocumentApp.ElementType.TABLE: 
    var newTable = 
    dstBody.insertTable(dstBody.getNumChildren()-1, dstChild); 
    copyTableCellByCell(dstChild, newTable); 
    break; 
.... 
} 

そして、これが最初で、各セルに取って代わるかもしれない再帰関数でありますそれを消去してオリジナルのテーブルからコンテンツをコピーすることができます。

function copyTableCellByCell(srcTable, dstTable) { 
    var numRows = dstTable.getNumRows(); 
    var dstRow, numCells, dstCell, actCellIndex; 
    for (var actRowIndex = 0; actRowIndex < numRows; actRowIndex++) { 
    dstRow = dstTable.getRow(actRowIndex); 
    numCells = dstRow.getNumCells(); 
    for (actCellIndex = 0; actCellIndex < numCells; actCellIndex++) { 
     dstCell = dstRow.getCell(actCellIndex); 
     dstCell.clear(); 
     var srcCell = srcTable.getCell(actRowIndex, actCellIndex); 
     var numCellChildren = srcCell.getNumChildren(); 
     for (var y = 0; y < numCellChildren; y++) { 
     var cellChild = srcCell.getChild(y); 
     var childCopy = cellChild.copy(); 
     switch(childCopy.getType()) { 
      case DocumentApp.ElementType.PARAGRAPH: 
      dstCell.insertParagraph(y, childCopy); 
      break; 
      case DocumentApp.ElementType.LIST_ITEM: 
      // that the GLYPH_TYPE doesn't get lost 
      var atts = childCopy.getAttributes(); 
      var 
      newListItem = dstCell.insertListItem(y, childCopy); 
      newListItem.setAttributes(atts); 
      break; 
      case DocumentApp.ElementType.TABLE: 
      var newTable = 
      dstCell.insertTable(y, childCopy); 
      copyTableCellByCell(cellChild, newTable); 
      break; 
     } 
     } 
     // remove the very first empty paragraph in the cell 
     while ((y = dstCell.getNumChildren()) > numCellChildren) { 
     dstCell.getChild(y - 1).removeFromParent(); 
     } 
    } 
    } 
} 

もちろん、これは微調整できます。 サーバーで作業する必要がないようにするには、インラインイメージを検索して選択するだけです。

これはどのような点でも役立ちます。 は、私がこのバグに対する解決策をコーディングどれも見つからなかっ

リチャード

0

、ご注意いただき、誠にありがとうございます。

イメージをソースドキュメントに「描画」として挿入します。

  1. イメージを挿入する必要がある表のセルをクリックします。
  2. 文書のメニューで「挿入」をクリックします。
  3. 「図を挿入」をクリックします。
  4. 描画ウィンドウで、挿入するイメージを追加します。
  5. 保存して閉じます。

結果は、テーブルの中に完全にコピーされたイメージとなります。

関連する問題