5

3 つの列と 2 つ (またはそれ以上) の行で構成される範囲があります。中央の列には次の式が含まれています。=TRANSPOSE(SPLIT(A1,","))

スクリプトは、その範囲を数式ではなくとして別のシートに移動 (カット) する必要があります。

google-apps-script には「PasteSpecial - 値」を実行する手段がありますか?

現在使用している回線は次のとおりです。

sheet1.getRange("F1:H3").moveTo(sheet2.getRange("A1")); 

sheet2 に移動する前に、これらの値をロックする方法を教えてもらえますか?

(参考までに: これにはコード ソリューションのみが必要です)

4

2 に答える 2

4

ソース範囲で getValues() を使用し、宛先で setValues() を使用します。範囲が同じディメンションであることを確認する必要があります。その後、ソースを clear() できます。

これは、仕事をするユーティリティ関数です。gist としても利用できます。範囲オブジェクトをパラメーターとして受け取ることに注意してください。

コード

/**
 * Move all values from source range to destination range. Upon
 * completion, source range will be cleared. Source values will
 * be moved into a destination range starting at the "top left"
 * of the destination range, using the dimensions of the source
 * range. This is a blind copy, with no overwrite test.
 *
 * @param {Range} source Range Object to take values from.
 * @param {Range} destination Range Object to receive values.
 *
 * @returns nothing
 */
function moveRange(source,destination) {
  var sourceSheet = source.getSheet();
  var destSheet = destination.getSheet();
  var sourceData = source.getValues();
  var dest = destSheet.getRange(
    destination.getRow(),        // Top row of destination
    destination.getColumn(),     // left col of destination
    sourceData.length,           // # rows in source
    sourceData[0].length);       // # cols in source (elements in first row)
  dest.setValues(sourceData);
  source.clear();
}

テスト機能

テストが成功すると、ソース範囲全体がクリアされ、その内容が宛先範囲に値としてのみ表示されます。移動先として指定されているものに関係なく、移動先の寸法は移動元の寸法と一致します。移動を固定するのは左上隅のみです。

function test_moveRange() {
  var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
  var destSheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[1];

  var source = sourceSheet.getRange("A7:C10");
  var destination = destSheet.getRange("C4:H2");
  moveRange(source,destination);
}
于 2013-04-18T18:35:52.173 に答える