Here’s an example code snippet that creates a new Google Sheet using Apps Script:
function createNewSheet() { var spreadsheet = SpreadsheetApp.create('New Sheet'); var sheet = spreadsheet.getActiveSheet(); // Perform any additional operations on the new sheet sheet.getRange('A1').setValue('Hello, World!'); }
In this code, the createNewSheet
function creates a new Google Sheet titled “New Sheet” using the SpreadsheetApp.create()
method. The spreadsheet
variable holds a reference to the newly created spreadsheet.
Next, the getActiveSheet()
method is used to get the active sheet within the newly created spreadsheet. This will be the first sheet by default.
You can perform any additional operations on the sheet
object as needed. In this example, the code sets the value “Hello, World!” in cell A1 of the new sheet using the getRange().setValue()
method.
You can run this function by calling it from another function, or by setting up a trigger to run it on a schedule or event. After running the function, a new Google Sheet will be created with the specified title, and the desired operations will be performed on the sheet.
Feel free to modify the code to suit your specific requirements and add more functionality as needed.