How to create new google spreadsheet using Google apps script

Google spreadsheet is similar to Microsoft Excel sheets and it contains most of the settings similar to Excel. Using Google app script you can create a new spreadsheet by executing the script.

To start writing the script, you should launch the Google app script editor page. Ensure that you’ve logged in with your Gmail account and navigate to https://script.google.com

Page open up with Untitled project and my function() as a default function. Double click the “Untitled project displayed at the top left of the page and give a Project name as you wish. Let’s say “My first Project”.

You can create a new spreadsheet with two different methods. However, the name of the methods is the same and it differs by the number of arguments.

Method 1

This method creates a spreadsheet with the given name. To create a new Spreadsheet, write the below function in the script editor page

function
myFunction() {

  var ssnew = SpreadsheetApp.create(“My
first sheet”);

 }

Method 

create(spreadsheet name)- It creates the spreadsheet with given name

Definition

ssnew- It denotes the variable name

SpreadsheetApp- It is the parent class of the Google Spreadsheet app.

create(“My first sheet”)- It is a method belonging to SpreadsheetApp.

It allows you to create a new spreadsheet with filename “My first sheet” which is given in the parameter of this method.

Execution

Execute the script by selecting the function name (Here it’s myFunction) and click on the Run Button or go to Run and select the function name. When it prompts for authorization, click on Continue to proceed. Then, it’ll ask for your permission to access your Google Drive if you’re running it for the first time. Click allow button.

Execution begins and gets completed in a few seconds. You can find “My first sheet” in your Google Drive.

This method creates a new spreadsheet called “My first sheet” with 1000 rows and 26 columns in your drive.

Method 2

This method creates a spreadsheet with given name and given a number of rows and columns.

Write the below function in the same page after myFunction but make sure that existing function names are unique.

function
myFunction1() {

  var ssnew = SpreadsheetApp.create(“My
Second sheet”,100,10);

 }

Method

create(spreadsheet name, number of rows, number of columns)- It creates a new spreadsheet with given name and specified number of rows and columns given in the 2nd and 3rd argument.

Execution

Go to Run and select the “myFunction1”. You’ll find a new spreadsheet “My Second sheet” with 100 rows and 10 columns in your google drive.

Please share your doubts via comments

Let me know your thoughts