LoginSignup
1
2

More than 3 years have passed since last update.

ふたつのスプレッドシートをひとつに合体する

Last updated at Posted at 2020-08-29

これは何

ふたつのスプレッドシートを、ひとつのスプレッドシートに合体する処理です。
より正確には、A・Bふたつのスプレッドシート内のシート郡を、新しく「C」というスプレッドシートに全コピーしています。
※UIからやるには数が多すぎる場合などに

image.png

コード

▼こんなかんじにURLを指定して
image.png

▼こんなスクリプトを実行


function combine_ss(){

  const ss_this = SpreadsheetApp.getActiveSpreadsheet();
  const ss_combine_url = ss_this.getRange("B1").getValue();
  const ss_sheet01_url = ss_this.getRange("B2").getValue();
  const ss_sheet02_url = ss_this.getRange("B3").getValue();

  const ss_combine = SpreadsheetApp.openByUrl(ss_combine_url);
  const ss_sheet01 = SpreadsheetApp.openByUrl(ss_sheet01_url);
  const ss_sheet02 = SpreadsheetApp.openByUrl(ss_sheet02_url);

  //シート合体
  indiv_sheet_conbime(ss_combine, ss_sheet01);
  indiv_sheet_conbime(ss_combine, ss_sheet02);

}


function indiv_sheet_conbime(ss_combine, ss_target){

  const sheet_list = ss_target.getSheets();

  for(var i=0; i < sheet_list.length; i++) {

    // シートと名前を取得
    const sheet_target = sheet_list[i];
    const sheet_target_name = sheet_target.getSheetName();

    const sheet_copied = sheet_target.copyTo(ss_combine);
    sheet_copied.setName(sheet_target_name);

  }

}

※スプレッドシート指定部分をループさせたりしたら、なんぼでも行けるとは思いますが、わりと時間がかるので起動時間には注意してください。

参考

【GAS】スプレッドシート内の全シートへのリンク一覧を作る - Qiita https://qiita.com/okNirvy/items/d1a2f4918cff8e63dcac

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2