开发者

creating new sheet and moving sheets between spreadsheet in google docs

开发者 https://www.devze.com 2023-04-05 12:31 出处:网络
I have 2 requirements: 1) I want to create a new sheet from existing sheet in current spreadsheet programmatically

I have 2 requirements:

1) I want to create a new sheet from existing sheet in current spreadsheet programmatically

2) I want to copy one sheet from one s开发者_如何学Gopreadsheet to another spreadsheet programmatically

Help appreciated.


Since you have not specified the environment/language. I think the easiest way to do this is using Apps Script as it's built-in in Google Spreadsheets.

Here is a sample code that does this:

function myFunction() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('SheetName');
  sheet.copyTo(ss).setName('NewName'); //copy to the same spreadsheet.
  //get a different spreadsheet (you can get its id in the url)
  var os = SpreadsheetApp.openById('any-spreadsheet-key-that-you-can-edit');
  //copy sourceSheet from one spreadsheet to another
  sheet.copyTo(os).setName('AnotherName');
}

To run this, just open the spreadsheet with the sheet you want to copy, click the menu Tools > Script editor.. Paste the code, Save and Run > myFunction

0

精彩评论

暂无评论...
验证码 换一张
取 消