Add a sheet

Here is how to add a sheet.

There are 8 functions to achieve this.

 

 

Source code

function addSheet() {
  // Get Spreadsheet Object
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();

  // Parameters
  var sheetIndex = 2;
  var templateSheet = spreadsheet.getSheetByName('Mini Dev Sheet');
  var options = {template: templateSheet};
  var sheetName = "New sheet";

  // Format
  spreadsheet.insertSheet();
  spreadsheet.insertSheet(sheetIndex);
  spreadsheet.insertSheet(sheetIndex, options);
  spreadsheet.insertSheet(options);
  spreadsheet.insertSheet(sheetName);
  spreadsheet.insertSheet(sheetName, sheetIndex);
  spreadsheet.insertSheet(sheetName, sheetIndex, options);
  spreadsheet.insertSheet(sheetName, options);
}

 

Format

SheetObject.insertSheet(sheetName, sheetIndex, options)

 

Parameters

(1) sheetName … You can edit new sheet’s name

(2) sheetIndex … You can edit a target position to be added

(3) options … you can select a original sheet to be copied

  var templateSheet = spreadsheet.getSheetByName('Mini Dev Sheet');
  var options = {template: templateSheet};
  spreadsheet.insertSheet(options);

Leave a Comment