Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

GASでシートが存在しない場合のみ作成

Posted at

#GASでシートが存在しない場合のみ作成する
調べてもGASでシートの存在チェックが出てこないので、必死に書いてみました。
ただ素人コーダーなので、いろいろと問題もあるかもしれません。

function SheetCopy() {
  const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var TargetSheet = spreadsheet.getSheetByName('原本');
  var date = new Date();
  var date = Utilities.formatDate( date, 'Asia/Tokyo', 'yyyy.MM.dd');
  try{
    var JudgeSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("foo_"+ date);
//判定用の変数で存在を判定したいシートの適当なところに空白を代入。
//これでエラーが出るかチェック
    JudgeSheet.getRange(100, 100).setValue("");
  }catch (e){
    var newSheet = TargetSheet.copyTo(spreadsheet);
    newSheet.setName(Utilities.formatString("foo_" + date));
  }
}
0
0
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

Comments

No comments

Let's comment your feelings that are more than good

Qiita Advent Calendar is held!

Qiita Advent Calendar is an article posting event where you post articles by filling a calendar 🎅

Some calendars come with gifts and some gifts are drawn from all calendars 👀

Please tie the article to your calendar and let's enjoy Christmas together!

0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Login to continue?

Login or Sign up with social account

Login or Sign up with your email address