1 | initial version |
Here is a sample Google Apps Script code that creates a new Google Sheets file with a particular range and sheets from an existing sheet when activated:
function createNewSheet() {
// Get the source spreadsheet and the specific sheet
var sourceSpreadsheet = SpreadsheetApp.getActive();
// Define the source sheet and the range to copy
var sourceSheet = sourceSpreadsheet.getSheetByName('Sheet1');
var sourceRange = sourceSheet.getRange('A1:D10');
// Create a new spreadsheet
var newSpreadsheet = SpreadsheetApp.create("New Spreadsheet");
// Copy the range to the new spreadsheet
var destinationSheet = newSpreadsheet.getActiveSheet();
sourceRange.copyTo(destinationSheet.getRange('A1'), {contentsOnly:true});
// Add additional sheets to the new spreadsheet
newSpreadsheet.insertSheet('Sheet2');
newSpreadsheet.insertSheet('Sheet3');
}
To activate this script, simply run the createNewSheet
function from the script editor or assign it to a button or trigger.