Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

Google Sheets script to duplicate a sheet at the beginning of the month?

I'm working on creating a budget on Google Sheets. I have two sheets for January (titled Jan Summary and Jan Transactions). I'm trying to create a script that will automatically duplicate those sheets at the beginning of each new month and change the sheet names that month as well. I'm not sure how to do this since I'm new to coding - does anyone have ideas?

question from:https://stackoverflow.com/questions/65622876/google-sheets-script-to-duplicate-a-sheet-at-the-beginning-of-the-month

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
function duplicateAndRenameSheet() {
  const prefix="Copy of ";//add in front of new name
  const postfix= ' ' + Utilities.formatDate(new Date(),Session.getScriptTimeZone,"E yyMMdd:HHmmss");//add to back of new name
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  let name=sh.getName();//active sheets name
  let nsh=ss.insertSheet({template:sh});//inserts a new sheet that's a copy of the active sheet
  nsh.setName(prefix + name + postfix);//renames the new sheet
}

Spreadsheet Methods

Sheet Methods


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...